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> char a[210][210]; char sum[210]; int cf[210]; int i; void add(int p,int j) { char k,t,r; t=a[p][j]-'0'; sum[j]+=t+cf[j]; cf[j]=0; r=sum[j]-'0'; if(r>9) { cf[j-1]=r/10; sum[j]=r%10; if(sum[0]>9&&j==0) { for(k=i;k>=0;k--) sum[k+1]=sum[k]; sum[0]=(sum[1]-'0')/10; sum[1]=(sum[1]-'0')%10; } } } int main() { int j,p,k; while(1) { memset(a,'\0',sizeof(a)); for(i=0;;++i) { scanf("%s",a[i]); if(a[i][0]=='0'&&a[i][1]=='\0') break; } memset(sum,0,sizeof(sum)); memset(cf,0,sizeof(cf)); strcpy(sum,a[0]); for(p=1;p<=i;p++) { k=strlen(a[p]); for(j=k-1;j>=0;j--) { add(p,j); } } printf("%s\n",sum); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator