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<iostream> using namespace std; int main() { char a[1000],b[1000],t; int i,j,x,lena,lenb; cin>>a; if(a[0]=='0' && a[1]==0) { cout<<"0"<<endl; return 0; } lena=strlen(a); for(;a[0]=='0';) { for(i=0;i<lena;i++) { a[i]=a[i+1]; } lena--; if(a[0]=='0' && a[1]==0) break; } for(j=0;j<(lena/2);) { if(j<(lena/2)) { t=a[j]; a[j]=a[lena-1-j]; a[lena-1-j]=t; j++; } } while (cin>>b) { if(b[0]=='0' && b[1]==0) break; lena=strlen(a); lenb=strlen(b); for(;b[0]=='0';) { for(i=0;i<lenb;i++) { b[i]=b[i+1]; } lenb--; if(b[0]=='0' && b[1]==0) break; } for(j=0;j<(lenb/2);) { if(j<(lenb/2)) { t=b[j]; b[j]=b[lenb-1-j]; b[lenb-1-j]=t; j++; } } if(lena<lenb) { for(i=0,j=0;j<lenb;i++,j++) { if(i<lena && j<lenb) x=a[i],a[i]=b[i],b[i]=x; if(i>=lena && j<lenb) a[j]=b[j]; } a[lenb]=0,b[lena]=0; x=lena,lena=lenb,lenb=x; } for(i=0;i<lenb;i++) { x=a[i]+b[i]-'0'-'0'; a[i]=(x%10)+'0'; if((x/10)==1) { if(a[i+1]>='0' && a[i+1]<'9') { a[i+1]++; continue; } for(j=i;a[j+1]=='9';j++) { a[j+1]='0'; if(a[j+2]<'9' && a[j+2]>='0') a[j+2]++; if(a[j+2]==0) a[j+2]='1',a[j+3]=0; } if(a[i+1]==0) a[i+1]='1',a[i+2]=0; } } } lena=strlen(a)-1; for(i=0;i<lena;i++,lena--) { t=a[i]; a[i]=a[lena]; a[lena]=t; } cout<<a<<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