Oracle
Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
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`.
For each test case, the single line contains an integer n (1≤n<1010000000).
112
233
1
35
Uncertain
In the first example, it is optimal to split $ 112 $ into $ 21 $ and $ 1 $, and their sum is $ 21 + 1 = 22 $.
In the second example, it is optimal to split $ 233 $ into $ 2 $ and $ 33 $, and their sum is $ 2 + 33 = 35 $.
In the third example, it is impossible to split single digit $ 1 $ into two parts.
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
using namespace std;
#define ll __int64
#define mod 100000007
#define esp 0.00000000001
const int N=1e5+,M=1e7+,inf=1e9+;
char a[M];
char b[M];
char c[M];
void add(char a[],char b[])//a=a+b
{
int i,j,k,sum=;
k=strlen(a)>strlen(b)?strlen(a):strlen(b);
a[k+]=;
for(i=strlen(a)-,j=strlen(b)-;i>=||j>=;i--,j--,k--)
{ if(i>=) sum+=a[i]-''; if(j>=) sum+=b[j]-'';
a[k]=sum%+''; sum/=;
}
if(sum) a[]=sum+'';
else strcpy(a,&a[]);
printf("%s\n",a);
}
int check(char *a)
{
int x=strlen(a);
if(x==)
return ;
for(int i=;i<x;i++)
if(a[i]!='')
return ;
return ;
}
int flag[];
int main()
{
int x,y,z,i,t;
int T;
scanf("%d",&T);
while(T--)
{
memset(flag,,sizeof(flag));
scanf("%s",a);
x=strlen(a);
for(i=;i<x;i++)
flag[a[i]-'']++;
int ji=;
int lu=;
for(i=;i<=;i++)
if(flag[i])
{
c[lu++]=''+i;
flag[i]--;
break;
}
for(i=;i>=;i--)
{
while(flag[i]!=)
{
b[ji++]=i+'';
flag[i]--;
}
}
b[ji]='\0';
c[lu]='\0';
if(check(b)&&check(c))
add(b,c);
else
printf("Uncertain\n");
}
return ;
}