标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 0 Accepted Submission(s): 0
Special Judge
#include<iostream> #include<cstdio> #include<cstring> using namespace std; char s[2000]; int ans[100][2000]; int gg[100]; int sub(int t,int len) { int i; for(i=len-1; i>=0; i--) { s[i]=s[i]-‘0‘-ans[t][i]; if(s[i]<0) { s[i]+=10+‘0‘; s[i-1]-=1; } else s[i]+=‘0‘; } for(i=0; i<len; i++) if(s[i]!=‘0‘) break; return i; } int main() { int i,j,t,T; while(scanf("%d",&T)!=EOF) { getchar(); for(int asd=1; asd<=T; asd++) { scanf("%s",s); memset(ans,0,sizeof(ans)); int pre=0,len=strlen(s); t=0; while(pre<len) { int sign=1; for(i=pre,j=len-1; i<=j; i++,j--) { ans[t][i]=ans[t][j]=s[i]-‘0‘; if(ans[t][j]>s[j]-‘0‘) sign=0; else if(ans[t][j]<s[j]-‘0‘)sign=1; } gg[t]=pre; if(sign==0) { i--; ans[t][i]-=1; while(i>=0&&ans[t][i]<0) { ans[t][i]+=10; ans[t][i-1]-=1; i--; } for(i=pre,j=len-1; i<=j; i++,j--) ans[t][j]=ans[t][i]; if(ans[t][pre]==0) { ans[t][len-1]=9; gg[t]=pre+1; } } pre=sub(t,len); t++; } printf("Case #%d:\n",asd); printf("%d\n",t); for(i=0; i<t; i++) { for(j=gg[i]; j<len; j++) printf("%d",ans[i][j]); printf("\n"); } } } return 0; }
2016中国大学生程序设计竞赛(长春)-重现赛 1010Ugly Problem 回文数 模拟
标签:
原文地址:http://www.cnblogs.com/GeekZRF/p/5931419.html