-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path10035.cpp
More file actions
43 lines (40 loc) · 1011 Bytes
/
Copy path10035.cpp
File metadata and controls
43 lines (40 loc) · 1011 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Author: btjanaka (Bryon Tjanaka)
// Problem: (UVa) 10035
#include <bits/stdc++.h>
#define GET(x) scanf("%d", &x)
#define GED(x) scanf("%lf", &x)
typedef long long ll;
using namespace std;
typedef pair<int, int> ii;
int main() {
while (true) {
int ch;
stack<int> a, b;
while ((ch = getchar()) != ' ') {
a.push(ch - '0');
}
while ((ch = getchar()) != '\n' && ch != EOF) {
b.push(ch - '0');
}
if (a.size() == 1 && b.size() == 1 && a.top() == 0 && b.top() == 0) break;
int res = 0;
int carry = 0;
while (!a.empty() || !b.empty()) {
int cur = (a.empty() ? 0 : a.top()) + (b.empty() ? 0 : b.top()) + carry;
carry = cur / 10;
if (cur >= 10) {
++res;
}
if (!a.empty()) a.pop();
if (!b.empty()) b.pop();
}
if (res == 0) {
printf("No carry operation.\n");
} else if (res == 1) {
printf("1 carry operation.\n");
} else {
printf("%d carry operations.\n", res);
}
}
return 0;
}