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 |
AC过此题的大哥,麻烦用BT数据测下,我不知道那里有误,小弟初学高精(附程序)#include<iostream.h> #include<string.h> #define M 10800 void add(int a[M],int b[M],int n)//运算结果保存在数组a中 {int i,t=0; for(i=1;i<n+2;i++) {a[i]=a[i]+b[i]+t; t=a[i]/10; a[i]=a[i]%10; } } void main() {int i,j,m,n,k,h,a[M]={0},b[M]; char r[102],s[102]; void add(int a[M],int b[M],int n); cin>>r; k=strlen(r); m=0; for(i=k-1;0<=i;i--) {m=m+1; a[m]=r[i]-'0'; } if(strlen(r)==1&&r[0]=='0') cout<<0; else { while(cin>>s) { n=0; h=strlen(s); if(h==1&&s[0]=='0') break; for(j=h-1;0<=j;j--) {n=n+1; b[n]=s[j]-'0'; } add(a,b,n); for(i=1;i<M;i++) b[i]=0; } for(i=M-1;i>1;i--) if(a[i]!=0) break; for(j=i;j>0;j--) cout<<a[j]; } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator