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 |
怎么还是wa?#include <stdio.h> #include <string.h> int main () { int n,t,i,j,carry,c,d; char a[1000],b[1000]; scanf ("%d",&n); for (t=1;t<=n;++t) { scanf ("%s%s",a,b); c=strlen(a); d=strlen(b); carry=0; if (c>d) { j=c-1; for (i=d-1;i>=0;--i) { a[j]=carry+a[j]+b[i]-48; carry=(a[j]-48)/2; a[j]=(a[j]-48)%2+48; j--; } if (carry) { for (i=c-d-1;i>=0;--i) { a[i]+=carry; carry=(a[i]-48)/2; a[i]=(a[i]-48)%2+48; } } printf ("%d ",t); if (carry) printf ("%d",carry); for (i=0;i<c-1;++i) if (a[i]-48) break; for (;i<c;++i) printf ("%c",a[i]); printf ("\n"); } //endif else { j=d-1; for (i=c-1;i>=0;--i) { b[j]=carry+b[j]+a[i]-48; carry=(b[j]-48)/2; b[j]=(b[j]-48)%2+48; j--; } if (carry) { for (i=d-c-1;i>=0;--i) { b[i]+=carry; carry=(b[i]-48)/2; b[i]=(b[i]-48)%2+48; } } printf ("%d ",t); if (carry) printf ("%d",carry); for (i=0;i<c-1;++i) if (b[i]-48) break; for (;i<c;++i) printf ("%c",b[i]); printf ("\n"); } } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator