hdu 5718 Oracle
来源:互联网 发布:绫致时装官方店淘宝 编辑:程序博客网 时间:2024/06/05 20:47
Oracle
Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 1251 Accepted Submission(s): 536
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 integern 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`.
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
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`.
Input
The first line of the input contains an integer T (1≤T≤10) , which denotes the number of test cases.
For each test case, the single line contains an integern (1≤n<1010000000) .
For each test case, the single line contains an integer
Output
For each test case, print a positive integer or a string `Uncertain`.
Sample Input
31122331
Sample Output
2235Uncertain题意:将一个数的每个数字重新排列后变成两个不为0的数字相加,使得这两个数相加之和最大。思路:先将数字当作字符串输入,然后数字排序,找到不为0的位置,然后进行高精度计算。代码:#include <iostream>#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;char c[11111111];char a[11111111];char b[11111111];int d[11111111];int main(){ int T; cin>>T; while(T--) { scanf("%s",c); int len=strlen(c); sort(c,c+len); int f; if(len==1||c[len-2]=='0') { cout<<"Uncertain"<<endl; continue;}int z;int i; for(i=0;i<len;i++) { if(c[i]!='0') { f=i; z=c[f]-'0'; break;}}int k=0;for(i=f;i>0;i--)c[i]=c[i-1];for(i=1;i<len;i++){d[i]=c[i]-'0';}d[1]+=z;for(i=1;i<len-1;i++){if(d[i]>9){d[i+1]++;d[i]-=10;}else break;}for(i=len-1;i>=1;i--){printf("%d",d[i]);}printf("\n"); } return 0;}
阅读全文
0 0
- Hdu 5718 Oracle【贪心】
- HDU 5718 Oracle
- HDU-5718 Oracle
- HDU 5718 Oracle
- hdu 5718 Oracle
- hdu 5718 oracle
- hdu 5718 Oracle(模拟)
- HDU 5718 Oracle【大数相加】
- HDU 5718 Oracle(大数)
- HDU 5718 oracle BestCoder 2nd Anniversary
- hdu 3456 Universal Oracle
- HDU 5718 BestCoder 2nd Anniversary Oracle (模拟)
- hdu 5718 大数模拟
- hdu
- hdu
- HDU
- hdu ()
- hdu
- Android四大组件之一 BroadcastReceiver解析
- 理解矩阵2
- 图像风格化总结
- android动画
- Apache服务器下ThinkPHP / ThinkCMF 伪静态解决方案
- hdu 5718 Oracle
- linux跟本地文件交互
- Java compiler level does not match the version of the installed Java project facet
- FMI飞马网 | 人工智能/大数据/程序/语言/项目管理/机器学习/Python书籍免费赠书
- 理解矩阵3
- oracle 数据库导入导出
- 何时使用 Em 与 Rem
- SpringMVC
- PHP 程序员学数据结构与算法之《栈》