-
Notifications
You must be signed in to change notification settings - Fork 0
/
Primary Arithmetic.cpp
61 lines (54 loc) · 1.23 KB
/
Primary Arithmetic.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
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<string>
#include<cmath>
typedef unsigned int ui;
typedef unsigned long int ul;
typedef unsigned long long int ull;
typedef long int li;
typedef long long int lli;
using namespace std;
main()
{
string n1,n2;
int l1,l2,i,j,x,carry;
while(1)
{
carry=0;
cin>>n1>>n2;
if(n1=="0" && n2 =="0")
break;
l1=n1.length();
l2=n2.length();
if(l1<l2)
{
swap(l1,l2);
swap(n1,n2);
}
reverse(n1.begin(),n1.end());
reverse(n2.begin(),n2.end());
for(i=0;i<l1;i++)
{
if(i<l2)
{
x=(n1[i]-'0')+(n2[i]-'0');
if(x>9)
carry++,n1[i+1]++;
}
else
{
x=n1[i]-'0';
if(x>9)
carry++,n1[i+1]++;
}
}
if(carry==0)
cout<<"No carry operation."<<endl;
else if(carry==1)
cout<<"1 carry operation."<<endl;
else
cout<<carry<<" carry operations."<<endl;
}
}