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 |
我开150跟300就过了In Reply To:开数组的,数组要开到1000.。。才过,再也不信题目给的条件了 Posted by:sw9416 at 2010-05-04 17:38:28 Source Code Problem: 1503 User: Belldandy Memory: 164K Time: 0MS Language: C Result: Accepted Source Code #include<stdio.h> #include<string.h> #define MAX 300 #define max 150 int main() { int i=0,len=0,c=0; int a[max]={0},ans[MAX]={0}; char temp[max]={0}; while(scanf("%s",temp)&&strcmp(temp,"0")) { for(i=0;temp[i];i++) { a[i]=temp[i]-'0'; } len=i; for(i=0,c=0;i<len;i++) { ans[MAX-1-i]+=a[len-1-i]+c; if(ans[MAX-1-i]>9) { ans[MAX-1-i]-=10; c=1; } else { c=0; } } if(c) { ans[MAX-1-i]+=1; c=0; } } for(i=0;i<MAX;i++) { if(ans[i]) { break; } } for(;i<MAX;i++) { printf("%d",ans[i]); } printf("\n"); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator