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 <string.h> #define M 110 #define MAX(a,b) a>b?a:b char s1[M]; char s2[M]; char k[M]; int main() { int len1,len2,i,flag,sum,d,ml,k1; flag=1; while(scanf("%s",&s1)!=EOF) { if(strcmp(s1,"0")==0) break; len1=strlen(s1); if(flag) { len2=len1; i=0; for(--len1;len1>=0;len1--) s2[i++]=s1[len1]; flag=0; } else { i=0; k1=len1; memset(k,'0',sizeof(k)); for(--k1;k1>=0;k1--) k[i++]=s1[k1]; ml=MAX(len1,len2); d=0; for(i=0;i<ml;i++) { sum=(s2[i]+k[i]-96+d); d=sum/10; s2[i]=sum%10+48; } if(d!=0) { s2[len2]=d+48; len2++; } } } for(--len2;len2>=0;len2--) if(s2[len2]!='0') break; for(;len2>=0;len2--) printf("%c",s2[len2]); return 1; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator