标签:
Time Limit:4000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Description
Input
Output
Sample Input
3 112 233 1
Sample Output
22 35 Uncertain
Hint
1 #include<cstdio> 2 #include<iostream> 3 #include<cstring> 4 #include<stdlib.h> 5 #include<algorithm> 6 using namespace std; 7 #define N 10000005 8 char s[N]; 9 int main() 10 { 11 int T,len,minn,mi,i; 12 scanf("%d",&T); 13 while(T--) 14 { 15 scanf("%s",&s); 16 len=strlen(s); 17 sort(s,s+len); 18 if(len==1||s[len-2]==‘0‘) 19 printf("Uncertain\n"); 20 else 21 { 22 for( i=0;i<len;i++) 23 if(s[i]!=‘0‘) 24 { 25 minn=i; 26 mi=s[i]-‘0‘; 27 break; 28 } 29 for(i=minn;i>0;i--) 30 s[i]=s[i-1];//接下来都是从1开始 31 s[1]+=mi; 32 for(i=1;i<len-1;i++) 33 { 34 if(s[i]>‘9‘) 35 { 36 s[i+1]++; 37 s[i]-=10; 38 } 39 else 40 break; 41 } 42 printf("%d",s[len-1]-‘0‘); 43 for(i=len-2;i>=1;i--) 44 printf("%c",s[i]); 45 printf("\n"); 46 } 47 } 48 return 0; 49 }
标签:
原文地址:http://www.cnblogs.com/Annetree/p/5824063.html