Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- using namespace std;
- int main()
- {
- string x,y;
- freopen("myDearInput.in", "r", stdin);
- while(cin>>x>>y && x!="0" && y!="0")
- {
- if ( x.size() < y.size())
- {
- for (int b=0 ; b <=(y.size()-x.size()) ;b++ )
- x.insert(x.begin(), '0');
- }
- else if ( x.size() > y.size())
- {
- for (int b=0 ; b <=(x.size()-y.size()) ;b++ )
- y.insert(y.begin(), '0');
- }
- string h=""; int carry=0 ,s=0 ,a=0;
- for(int i=(x.size()-1) ;i>=0 ;i--)
- {
- int f=x[i]-48 , j=y[i]-48 ;
- s=f+j+carry;
- if (s>9)
- {
- h.insert(h.begin() ,((s-10)+48));
- carry=1;
- a++;
- if (i==0)
- h.insert(h.begin() ,((s/10)+48));
- }
- else
- {
- h.insert(h.begin() ,(s+48));
- carry=0;
- }
- }
- if (a==0)
- cout<<"No carry operation.";
- else if (a==1)
- cout<<"1 carry operation.";
- else
- cout<<a<<" carry operations.";
- cout<<endl;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment