Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
不好意思再次纠正一下。In Reply To:不好意思纠正一下。 Posted by:hefei2 at 2006-01-12 11:15:25 #include <iostream> #include <string> using namespace std; int main() { string a1,a2; cin>>a1>>a2; while(!(a1=="0" && a2=="0")) { int l1 = 10 - a1.length(); int l2 = 10 - a2.length(); int carry; carry = 0; int i; int c; c = 0; for(i=1;i<=l1;i++)a1 = "0" + a1; for(i=1;i<=l2;i++)a2 = "0" + a2; //cout<<a1<<" "<<a2<<endl; for(i=9;i>=0;i--) { char t1,t2; t1 = a1[i]; t1-='0'; t2 = a2[i]; t2-='0'; if(t1+t2+c>=10)carry++; c = (t1 + t2)/10; } if(carry==0)cout<<"No carry operation."<<endl; else if(carry>1)cout<<carry<<" carry operations."<<endl; else if(carry==1)cout<<"1 carry operation."<<endl; cin>>a1>>a2; } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator