Oracle 诶,弱鸡的ACM第二天!

来源:互联网 发布:js触发select下拉事件 编辑:程序博客网 时间:2024/06/05 20:32

<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
31122331
Sample Output
2235Uncertain
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".
输入描述
第一行一个整数$ T $ $ (1 \le T \le 10) $,代表数据组数。接下来$ T $行,每行一个正整数$ n $ $ (1 \le n < 10 ^ {10000000}) $。
输出描述
对于每组数据,输出一个整数表示最大的和。若不存在一种方案,输出"Uncertain".
输入样例
31122331
输出样例
2235Uncertain
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 10000000int 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];    //若只有一个数字,其他为0if (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