Oracle

 

<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">和隔壁一样在做BC,然而真是弱到渣,做了一上午。</span>

 

 

 

Oracle

 

 Accepts: 599

 

 Submissions: 2576

 Time Limit: 8000/4000 MS (Java/Others)

 

 Memory Limit: 262144/262144 K (Java/Others)

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 intotwo positive integers without leading zeroes, 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}) $.

Output

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

Sample Input

3
112
233
1

Sample Output

22
35
Uncertain

Hint

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.

 

 

 

译文版:

 

Oracle

 

 Accepts: 599

 

 Submissions: 2576

 Time Limit: 8000/4000 MS (Java/Others)

 

 Memory Limit: 262144/262144 K (Java/Others)

问题描述

曾经有一位国王,统治着一片未名之地。他膝下有三个女儿。

三个女儿中最年轻漂亮的当属Psyche。她的父亲不确定她未来的命运,于是他来到Delphi神庙求神谕。

神谕可以看作一个不含前导零的正整数$ n $。

为了得到真正的预言,他可以将$ n $的各个数位重新排列,并将其分成两个不含前导零的正整数。

请你帮助他求出这两个正整数最大的和。如果不存在这样的两个正整数,输出"Uncertain".两个不含前导零的正整数。

请你帮助他求出这两个正整数最大的和。如果不存在这样的两个正整数,输出"Uncertain".

输入描述

第一行一个整数$ T $ $ (1 \le T \le 10) $,代表数据组数。

接下来$ T $行,每行一个正整数$ n $ $ (1 \le n < 10 ^ {10000000}) $。

输出描述

对于每组数据,输出一个整数表示最大的和。若不存在一种方案,输出"Uncertain".

输入样例

3
112
233
1

输出样例

22
35
Uncertain

Hint

对于第一组数据,最优方案是将$ 112 $分成$ 21 $和$ 1 $,最大的和为$ 21 + 1 = 22 $。

对于第二组数据,最优方案是将$ 233 $分成$ 2 $和$ 33 $,最大的和为$ 2 + 33 = 35 $。

对于第三组数据,显然无法将一个数位分成两部分。

建议使用效率较高的读入方式。建议使用效率较高的读入方式。

 

 

 

我的代码:

 

<pre name="code" class="cpp">#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 10000000
int SS[N]={0};
char laji[N]={0};
int main()
{
	int ca,num,temp,temp1,flag,i,j,k,z,len;
	int s[10]={0};
	scanf("%d",&ca);
	while (ca--){
		memset(s,0,sizeof(s));
		memset(SS,0,sizeof(SS));
		scanf("%s",laji);       //char的形式读入
		len=strlen(laji);
		for (i=0;i<len;i++){    //转为int数组
			s[laji[i]-'0']++;
		}           
		temp1 = temp = 0;
		for (i=1;i<10;i++) temp += s[i];    //若只有一个数字,其他为0
		if (temp==1) printf("Uncertain\n");
		else {
            for (i=1;i<9;i++)               //以下为若只有一个1-8的数字和全部都是9的情况
            {                               //其实没篮子用,无视吧- -
                if (s[i]==1) z=i;
                temp1+=s[i];
            }
			if (temp1==1&&s[9]!=0){
				printf("1");
				for (i=0;i<s[9]-1;i++) printf("0");
					printf("%d\n",(z+9)%10);
			}
			else{                           //无视一直到这里
                for (i=1;i<10;i++){         //找最小的不为0的数字,并在数组里消去一个此数字
				if (s[i]==0) continue;
				else {
					s[i]--;
					flag = i;
					break;
				}
			}
			k=0;
			for (i=9;i>=0;i--){             //输出到一个数组方便处理和输出
                if (s[i]==0) continue;
				for (j=0;j<s[i];j++){
					SS[k]=i;
					k++;
				}
			}
			SS[k-1]+=flag;                  //最小的数字和数组最后的不为0的数字相加
			for(i=0;i<k;i++) printf("%d",SS[i]);
				printf("\n");

			}
		}
	}
}

 

 

 

 

 

 

多有疏漏,若有不妥之处,请勿波及他人...

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值