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<iostream> #include<string.h> using namespace std; int JH(char * a) { int l,i; char b; l=strlen(a); for(i=0;i<l/2;i++) { b=a[i]; a[i]=a[l-1-i]; a[l-1-i]=b; } return 0; } int addition(char * a,char * b) { int l1,l2,l,i; l1=strlen(a); l2=strlen(b); l=(l1>l2)?l1:l2; for(i=l1;i<l;i++) a[i]='0'; for(i=l2;i<l;i++) b[i]='0'; for(i=0;i<l;i++) { b[i]=b[i]+a[i]-48; if(b[i]>=58) { b[i]-=10; if(b[i+1]>47&&b[i+1]<58) b[i+1]+=1; else b[i+1]='1'; } } return 0; }; int main () { char a[100],b[101]="0"; int l,i,j=0,h=0; while(EOF) { while(1) { gets(a); h++; if(h>=100) goto XXX; JH(a); if(strcmp(a,"0")==0) break; addition(a,b); } l=strlen(b); for(i=l-1;i>=0;i--) { if(b[i]=='0') j++; else break; }; JH(b); for (i=j;i<l;i++) cout<<char(b[i])<<flush; strcpy(b,"0"); } XXX:return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator