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 |
诚心请教,为什么过不了?当前的提示中的数据都过了#include <stdio.h> #include <memory.h> #include <cstring> int main() { int n,m=1; scanf("%d",&n); char a[1001],b[1001]; int c[1001]; memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); memset(c,0,sizeof(c)); while( m<=n ) { int i=0,j=0,alen=0,blen=0; while( scanf("%s%s",&a,&b)==2 ) { alen=strlen(a); blen=strlen(b); int clen=0,carry=0; int d=(int)b[0]; int p=0,q=0; while( alen>0 && blen>0 ) { p=(int)a[alen-1]; q=(int)b[blen-1]; p-=48; q-=48; c[clen]=carry + p + q ; if( c[clen]>=2 ) { carry=1; } else { carry=0; } if( c[clen]>=2 ) { c[clen]-=2; } alen--; blen--; clen++; } if( alen>0 ) { while( alen>0 ) { p=(int)a[alen-1]; p-=48; c[clen]=p+carry; if( c[clen]>=2 ) { c[clen]-=2; carry=1; } else { carry=0; } clen++; alen--; } } if( blen>0 ) { while( blen>0 ) { q=(int)b[blen-1]; q-=48; c[clen]=q+carry; if( c[clen]>=2 ) { c[clen]-=2; carry=1; } else { carry=0; } clen++; blen--; } } if( alen<=0 && blen<=0 ) { if( carry==1 ) { c[clen]=1; } } printf("%d ",m); while( c[clen]==0 && clen>0 ) { clen--; } for( int k=clen;k>=0;k-- ) { printf("%d",c[k]); } printf("\n"); m++; } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator