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 |
Re:我的电脑上运行是对的,而提交后wrong answer.不知输入数组int a[100000]够不够大.若不够怎样设?In Reply To:我的电脑上运行是对的,而提交后wrong answer.不知输入数组int a[100000]够不够大.若不够怎样设? Posted by:wangfanking at 2005-09-02 10:16:32 #include<stdio.h> char *ch=new char[30]; long int input() { long int i,sum=0; scanf("%s",ch); if(ch[0]=='0') return 0; for(i=0;ch[i]!=0;i++) sum+=ch[i]-'0'; return sum; } int main() { long int i,j,k;long int sum; i=input(); while(i) { sum=0; while(i>0){ while(i>0) { j=i%10;//printf("%ld\n",i); i=i/10; sum+=j; } if(sum>=10) {i=sum;sum=0;} } printf("%ld\n",sum); i=input(); } return 0; } 看看我的,可以参考一下,写得不好不要见怪,数组30就可以了 Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator