标签:
Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 325 Accepted Submission(s): 139
#include<iostream> #include<stdio.h> #include<string> #include<string.h> using namespace std; char num[10000005]; int ans[10000005]; int main() { int t; scanf("%d",&t); getchar(); while(t--) { int i=0; int ge[10]; for(int j=0; j<10; j++) ge[j]=0; scanf("%s",num); int len=strlen(num); if(len<=1) { printf("Uncertain\n"); } else { for(int i=0;i<len;i++){ ge[num[i]-‘0‘]++; } int cnt=0; for(int i=9;i>=0;i--){ for(int j=0;j<ge[i];j++){ ans[cnt++]=i; } } // for(int i=0;i<cnt;i++) cout<<ans[i]<<" "; int flag=1; if(ans[cnt-1]==0){ flag=0; for(int i=cnt-2;i>0;i--){ if(ans[i]!=0){ flag=1; ans[cnt-1]=ans[i]; ans[i]=0; break; } } } if(!flag){ printf("Uncertain\n"); continue; } int tmp=0; // for(int j=0; j<len; j++) cout<<ans[j]<<endl; //cout<<len; for(int j=len-2; j>=0; j--) { ans[j]=ans[j]+tmp; if(j==len-2) ans[j]=ans[j]+ans[len-1]; if(ans[j]>=10) { ans[j]-=10; tmp=1; } else { tmp=0; } } if(tmp) { printf("1"); } for(int i=0; i<=len-2; i++) printf("%d",ans[i]); printf("\n"); } } return 0; }
标签:
原文地址:http://www.cnblogs.com/superxuezhazha/p/5680203.html