首页 > 代码库 > HDU 5718 Oracle(高精度)
HDU 5718 Oracle(高精度)
Time Limit:4000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Description
There is once a king and queen, rulers of an unnamed city, who have three daughters of conspicuous beauty.
The youngest and most beautiful is Psyche, whose admirers, neglecting the proper worship of the love goddess Venus, instead pray and make offerings to her. Her father, the king, is desperate to know about her destiny, so he comes to the Delphi Temple to ask for an oracle.
The oracle is an integer $ n $ without leading zeroes.
To get the meaning, he needs to rearrange the digits and split the number into <b>two positive integers without leading zeroes</b>, and their sum should be as large as possible.
Help him to work out the maximum sum. It might be impossible to do that. If so, print `Uncertain`.
The youngest and most beautiful is Psyche, whose admirers, neglecting the proper worship of the love goddess Venus, instead pray and make offerings to her. Her father, the king, is desperate to know about her destiny, so he comes to the Delphi Temple to ask for an oracle.
The oracle is an integer $ n $ without leading zeroes.
To get the meaning, he needs to rearrange the digits and split the number into <b>two positive integers without leading zeroes</b>, and their sum should be as large as possible.
Help him to work out the maximum sum. It might be impossible to do that. If so, print `Uncertain`.
Input
The first line of the input contains an integer $ T $ $ (1 \le T \le 10) $, which denotes the number of test cases.
For each test case, the single line contains an integer $ n $ $ (1 \le n < 10 ^ {10000000}) $.
For each test case, the single line contains an integer $ n $ $ (1 \le n < 10 ^ {10000000}) $.
Output
For each test case, print a positive integer or a string `Uncertain`.
Sample Input
31122331
Sample Output
2235Uncertain
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 else21 {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 }
HDU 5718 Oracle(高精度)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。