hdu 5718 Oracle

来源:互联网 发布:绫致时装官方店淘宝 编辑:程序博客网 时间:2024/06/05 20:47

Oracle

Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 1251    Accepted Submission(s): 536


Problem 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`.
 

Input
The first line of the input contains an integer T (1T10), which denotes the number of test cases.

For each test case, the single line contains an integer n (1n<1010000000).
 

Output
For each test case, print a positive integer or a string `Uncertain`.
 

Sample Input
31122331
 

Sample Output
2235Uncertain
题意:将一个数的每个数字重新排列后变成两个不为0的数字相加,使得这两个数相加之和最大。
思路:先将数字当作字符串输入,然后数字排序,找到不为0的位置,然后进行高精度计算。
代码:
#include <iostream>#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;char c[11111111];char a[11111111];char b[11111111];int d[11111111];int main(){    int T;    cin>>T;    while(T--)    {    scanf("%s",c);    int len=strlen(c);    sort(c,c+len);    int f;    if(len==1||c[len-2]=='0')    {    cout<<"Uncertain"<<endl;    continue;}int z;int i;    for(i=0;i<len;i++)    {    if(c[i]!='0')    {    f=i;    z=c[f]-'0';    break;}}int k=0;for(i=f;i>0;i--)c[i]=c[i-1];for(i=1;i<len;i++){d[i]=c[i]-'0';}d[1]+=z;for(i=1;i<len-1;i++){if(d[i]>9){d[i+1]++;d[i]-=10;}else break;}for(i=len-1;i>=1;i--){printf("%d",d[i]);}printf("\n");    }    return 0;}