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 |
注意前导零,可用C++中的string类型,要用G++交 附代码#include <iostream> #include <cstring> #include <cstdio> using namespace std; int a[100005],b[100005],len,m; string read; int Max(int a,int b) { if(a>b)return a; return b; } void gjadd() { int mx=Max(len,m),c=0; m=mx; for(int i=1;i<=mx;i++) { a[i]=a[i]+b[i]+c; c=a[i]/10; a[i]%=10; } if(c>0)a[++m]=c; } int main() { while(true) { memset(b,0,sizeof(b)); cin>>read; if(read=="0")break;//string 判断是否read中只有'0' len=read.length(); for(int i=1;i<=len;i++)b[i]=read[len-i]-48; gjadd(); } for(int i=m;i>=1;i--)printf("%d",a[i]); printf("\n"); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator