-
Notifications
You must be signed in to change notification settings - Fork 0
/
10035.cpp
64 lines (54 loc) · 1.36 KB
/
10035.cpp
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
char a[11], b[11], tmp;
int indexA, indexB, sum;
bool flag;
while (true) {
scanf("%s %s", a, b);
if (a[0] == '0' && b[0] == '0') break;
indexA = 0;
indexB = 0;
while (a[indexA] != '\0')
indexA++;
while (b[indexB] != '\0')
indexB++;
sum = 0;
indexA--;
indexB--;
flag = false;
while (indexA > -1 && indexB > -1) {
tmp = a[indexA--] + b[indexB--] - '0';
if (flag) tmp++;
if (tmp > '9') {
sum++;
flag = true;
// cout << indexA << endl;
}
else
flag = false;
}
while (indexA > -1 && flag) {
if (a[indexA--] == '9')
sum++;
else
flag = false;
}
while (indexB > -1 && flag) {
if (b[indexB--] == '9')
sum++;
else
flag = false;
}
if (sum == 0)
cout << "No carry operation." << endl;
else if (sum == 1)
cout << "1 carry operation." << endl;
else
cout << sum << " carry operations." << endl;
}
return 0;
}