-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10035.cpp
64 lines (52 loc) · 1016 Bytes
/
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
/*
10035 - Primary Arithmetic
*/
#include <bits/stdc++.h>
using namespace std;
int main()
{
int carry;
int a,b, ans;
while(scanf("%d %d", &a, &b))
{
if(!a && !b) break;
ans = 0;
carry = 0;
while(1)
{
int tmpA = a%10;
int tmpB = b%10;
if(tmpA + tmpB + carry >= 10 )
{
carry = (tmpA + tmpB + carry)/10;
}
else
carry = 0;
if(carry) ans++;
a/=10;
b/=10;
//if(carry == 1)
// ans++;
if(a == 0 && b == 0)
break;
}
if(ans == 0)
printf("No carry operation.\n");
else if(ans == 1)
printf("1 carry operation.\n");
else
printf("%d carry operations.\n", ans);
}
return 0;
}
/*
Sample Input
123 456
555 555
123 594
0 0
Sample Output
No carry operation.
3 carry operations.
1 carry operation.
*/