|
|
вернуться в форумWhy I got WA? my program as follow: #include <iostream.h> void main() { static long int n,a[112000],b[112000],i,t=0; int a1,b1,t1; cin>>n; t1=n%9; for(i=1;i<=n%9;i++) { cin>>a1>>b1; a[0]*=10; b[0]*=10; a[0]+=a1; b[0]+=b1; } if(n%9==0) t=0; else t=1; for(;i<=n;i++) { cin>>a1>>b1; a[t]*=10; b[t]*=10; a[t]+=a1; b[t]+=b1; if((i-t1)%9==0) t++; } for(i=t-1;i>0;i--) { a[i-1]+=(a[i]+b[i])/1000000000; a[i]=(a[i]+b[i])%1000000000; } a[0]=a[0]+b[0]; cout<<a[0]; for(i=1;i<t;i++) { cout.fill('0'); cout.width (9); cout<<a[i]; } } I store 9 digits in a long type.What's wrong with it? Can someone give me some test data And I too. Why ? Послано sikee8 17 апр 2002 14:32 i don't know whats wrong your program. as my. #include <iostream.h> int main () { bool first = true; long n,n9,a,b,back=0,i=0; cin >> n; while (i<=n) { n9=-1; do { cin >> a >> b; i++; if (first && a==0 && b==0) continue; n9++; } while ( ((a+b) == 9 || (first && !a && !b)) && (i<n) ); if (a+b>9) { cout << back + 1; for (long j=1; j<=n9; j++) cout << 0; } if (a+b<9) { if (!first) cout << back; for (long j=1; j<=n9; j++) cout << 9; } back = (a+b)%10; if (i==n) { if (a+b==9) { if (!first) cout << back; for (long j=1; j<=n9; j++) cout << 9; } cout << back; return 0; } first = false; } return 0; //never } |
|
|