计数排序 +高精度加法不太擅长这种题做个标记
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdlib>
#include<cmath>
#define pi acos(-1.0);
#define LL long long
using namespace std;
int t,n;
char a[10000005],b[5],c;
short st[10000005];
const int L=110;
int sum[12];
int main()
{
scanf("%d",&t);
getchar();
while(t--)
{
memset(sum,0,sizeof(sum));
int l = 0;
while(char c = getchar())
{
if(c=='\n')break;
sum[c-'0']++;
l++;
}
int la = 0,lb = 0;
if(sum[0]==l-1)printf("Uncertain\n");
else{
for(int i=1;i<=9;i++)
if(sum[i])
{
b[lb++] = i+'0';
sum[i]--;
break;
}
b[lb] = '\0';
for(int i=9;i>=0;i--)
while(sum[i])
{
a[la++] = i+'0';
sum[i]--;
}
a[la] = '\0';
int jin = 0;
int i,j,l1 = 0;
for(i=la-1,j=lb-1;i>=0&&j>=0;i--,j--)
{
st[l1++] = (a[i]-'0'+b[j]-'0'+jin)%10;
jin = (a[i]-'0'+b[j]-'0'+jin)/10;
}
for(;i>=0;i--)
{
st[l1++] = ((a[i]-'0'+jin)%10);
jin = (a[i]-'0'+jin)/10;
}
for(;j>=0;j--)
{
st[l1++] = ((b[j]-'0'+jin)%10);
jin = (b[j]-'0'+jin)/10;
}
if(jin)printf("1");
for(int i=l1-1;i>=0;i--) putchar(st[i]+'0');
printf("\n");
}
}
return 0;
}