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 |
why wa? 困惑,感觉该注意的都注意了啊!#include "iostream" #include "string" const int MAX = 11; using namespace std; char a[MAX],b[MAX],a1[MAX],b1[MAX]; int main(void) { int m,n,i,add,Max,temp,ans; while(scanf("%s%s",a,b) != EOF) { memset(a1,'0',sizeof(a1)); memset(b1,'0',sizeof(b1)); if(a[0] == 0 && b[0] == 0 && strlen(a) == 1 && strlen(b) ==1) break; ans = 0; m = strlen(a); n = strlen(b); for(i=m-1;i>=0;i--) a1[m-i-1] = a[i]; for(i=n-1;i>=0;i--) b1[n-i-1] = b[i]; // puts(a1); // puts(b1); add = 0; Max = m>n?m:n; for(i=0;i<Max;i++) { if(add == 0) { temp = a1[i]-'0' + b1[i]-'0'; if(temp >= 10) { ans++; add = 1; } else add = 0; } else { temp = a1[i]-'0' + b1[i]-'0' + add; if(temp >= 10) { ans++; add = 1; } else add = 0; } } if(ans == 0) cout<<"No carry operation."<<endl; else if(ans == 1) cout<<"1 carry operation."<<endl; else cout<<ans<<" carry operations."<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator