-
Notifications
You must be signed in to change notification settings - Fork 0
/
p10035.cpp
55 lines (51 loc) · 1.26 KB
/
p10035.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
#include<iostream>
#include <string>
#include<algorithm>
using namespace std;
int main()
{
string a,b;
int c,d;
while(cin>>a>>b){
if(a=="0" && b=="0")
break;
else{
reverse(a.begin(),a.end());
reverse(b.begin(),b.end());
c=a.size();
d=b.size();
if(c<d){
swap(a,b);
swap(c,d);
}
int counter=0,t=0;
for(int i=0;i<d;i++){
int x,y;
x=a[i]-48;
y=b[i]-48;
if((x+y+t)>9){
t=1;
counter++;
}
else
t=0;
}
for(int i=d;i<c;i++){
int x=a[i]-48;
if((x+t)>9){
t=1;
counter++;
}
else
t=0;
}
if(counter==0)
cout<<"No carry operation."<<endl;
else if(counter==1)
cout<<"1 carry operation."<<endl;
else
cout<<counter<<" carry operations."<<endl;
}
}
return 0;
}