Oracle【BC】
2016-07-17 22:00
225 查看
Oracle
Accepts: 631
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 nn
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
Input
The first line of the input contains an integer T TT(1≤T≤10)
(1 \le T \le 10) (1≤T≤10),
which denotes the number of test cases.
For each test case, the single line contains an integer n nn(1≤n<1010000000)
(1 \le n < 10 ^ {10000000})(1≤n<1010000000).
Output
For each test case, print a positive integer or a string
Sample Input
Copy
Sample Output
Copy
题意:把一串数分为两部分正数,要求和值最大,否则,输出”Uncertain”
分开判断 一位数、两位数,多位数则判断只有一位数不为0的情况,然后进行处理:sort升序排序,只要形成组合 sum = 最大的数+最小的正数【一位数不为0】
Accepts: 631
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 nn
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 TT(1≤T≤10)
(1 \le T \le 10) (1≤T≤10),
which denotes the number of test cases.
For each test case, the single line contains an integer n nn(1≤n<1010000000)
(1 \le n < 10 ^ {10000000})(1≤n<1010000000).
Output
For each test case, print a positive integer or a string
Uncertain.
Sample Input
Copy
3 112 233 1
Sample Output
Copy
22 35 Uncertain Hint In the first example, it is optimal to split 112 112 112 into 21 21 21 and 1 1 1, and their sum is 21+1=22 21 + 1 = 22 21+1=22. In the second example, it is optimal to split 233 233 233 into 2 2 2 and 33 33 33, and their sum is 2+33=35 2 + 33 = 35 2+33=35. In the third example, it is impossible to split single digit 1 1 1 into two parts.
题意:把一串数分为两部分正数,要求和值最大,否则,输出”Uncertain”
分开判断 一位数、两位数,多位数则判断只有一位数不为0的情况,然后进行处理:sort升序排序,只要形成组合 sum = 最大的数+最小的正数【一位数不为0】
#include <algorithm> #include <iostream> #include <cstring> #include <cstdio> #include <ctime> #include <set> #include <map> #include <cmath> using namespace std; const int maxn = 10000100; int n, m, k; char s[maxn],a[maxn]; int main(){ scanf("%d",&n); while(n--){ memset(a,'\0',sizeof(a)); scanf("%s",s); int len = strlen(s); if(len==1){//一位数 printf("Uncertain\n"); continue; } if(len==2 ){//两位数 if(s[0]=='0'||s[1]=='0') printf("Uncertain\n"); else printf("%d\n",s[0]-'0'+s[1]-'0'); continue; } sort(s,s+len);//升序 k = 0; int flag = 1; int si = -1; int cnt0 = 0; for(int i=0;i<len;i++){ if(s[i]!='0' && flag){ si = i;//第一次不为0 flag = 0; continue; } if(s[i]=='0')cnt0++; a[k++] = s[i]; } if(cnt0>=len-1) {//只有一个不为0的数 printf("Uncertain\n"); continue; } a[0] += s[si]-'0'; if(a[0] > '9'){ a[0] -= 10; a[1] += 1; } m = k; for(int i=1;i<k;i++){ if(i==k-1&&a[i]>'9') { m++; a[i] -= 10; a[i+1] = '1'; continue; } if(a[i] > '9'){ a[i] -= 10; a[i+1] += 1; } } for(int i=m-1;i>=0;i--){ printf("%c",a[i]); } printf("\n"); } return 0; }
相关文章推荐
- BestCoder 2nd Anniversary - 1001 Oracle
- 21.Which three statements are true about logical structures of the Oracle database? (Choose three.)
- ORACLE基本数据类型总结
- BestCoder 2nd Anniversary #1001-oracle
- Oracle 建立索引及SQL优化
- oracle创建表空间以及用户角色Demo
- oracle学习笔记 SQL语句执行过程剖析讲课
- oracle 9i/10g/11g(11.2.0.3)安装包和PATCH下载地址汇总
- 用python读取oracle函数返回值
- Maven 引入oracle jdbc jar包
- OCA笔记04------完整性约束
- ORACLE知识点整理之一
- 安装和使用Oracle VM VirtualBox中的要点,注意事项和遇到的问题
- OCA笔记03------用户、角色和权限
- 在Oracle VM VirtualBox中如何安装64位虚拟机系统
- Oracle——分区表
- oracle 行转列应用
- Oracle RMAN异机恢复归档RMAN-07518(供日志挖掘使用)及修改dbid步骤
- ORACLE删除某用户下所有对象
- 一种高效的 vector 四则运算处理方法