| ||||||||||
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:注意测试【999999+1】这种数据In Reply To:注意测试【999999+1】这种数据 Posted by:sunchy at 2014-08-01 00:38:28 我的代码这个数据输入答案错误 但是却AC了 这道题没有测试数据不包括该种类型, 不过自己应该试着去改进一下 毕竟水过不算真正的掌握了 #include<stdio.h> #include<string.h> char s[110]; int ans[10000]; int main() { int maxlen=-1,flag=0; memset(ans,0,sizeof(ans)); while(scanf("%s",s)) { int p=0; if(strlen(s)==1&&s[0]=='0') break; int len=strlen(s)-1; while(len>=0) { if((s[len]-'0')+ans[p]>=10) { ans[p]=((s[len]-'0')+ans[p])%10; p++; ans[p]++; } else { ans[p]=(s[len]-'0')+ans[p]; p++; } len--; } if(maxlen<p) maxlen=p; } for(int i=maxlen;i>=0;i--) { if(!flag&&ans[i]==0) continue; else { flag=1; printf("%d",ans[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