BestCoder 2nd Anniversary 1001/hdu5718 Oracle
来源:互联网 发布:域名后缀cc 编辑:程序博客网 时间:2024/04/30 16:12
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5718
题目:
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−90-90−9这101010个数字分别有多少个。不难看出,最小的一个存在的数字和其余的数字降序排列的相加就是答案,但是最小的那个数字不能是000,因为题面上说明是正整数。将这两个数加起来时,注意处理进位问题。考虑无解的情况,即一串数字中仅存在111个非000数字或不存在。
#include <iostream>#include<cstdio>#include<cstring>#define N 11000000using namespace std;int a[11],b[N];char s[N];int main(){ int T; cin>>T; while(T--) { scanf("%s",s); int n=strlen(s); memset(a,0,sizeof(a)); for(int i=0;i<n;i++) a[s[i]-'0']++; int tp; int flag=0; for(int i=1;i<10;i++) if(a[i]) { flag+=a[i]; if(flag>=2) break; } if(flag<2) { cout<<"Uncertain"<<endl; continue; } for(int i=1;i<10;i++) if(a[i]) { a[i]--; tp=i; break; } int m=0; memset(b,0,sizeof(b)); for(int i=0;i<10;i++) for(int j=1;j<=a[i];j++) b[m++]=i; for(int i=0;i<=m&&tp;i++) { int t=b[i]+tp; tp=t/10; b[i]=t%10; } if(b[m]) printf("%d",b[m]); for(int i=m-1;i>=0;i--) cout<<b[i]; cout<<endl; }}
0 0
- BestCoder 2nd Anniversary 1001/hdu5718 Oracle
- BestCoder 2nd Anniversary #1001-oracle
- BestCoder 2nd Anniversary - 1001 Oracle
- BestCoder 2nd Anniversary Oracle
- BestCoder 2nd Anniversary Oracle
- BestCoder 2nd Anniversary--1001Oracle
- HDU 5718 oracle BestCoder 2nd Anniversary
- BestCoder 2nd Anniversary
- BestCoder 2nd Anniversary
- BestCoder 2nd Anniversary
- BestCoder 2nd Anniversary
- BestCoder 2nd Anniversary
- BestCoder 2nd Anniversary 1001~1003
- BestCoder 2nd Anniversary-1005
- BestCoder 2nd Anniversary Arrange
- BestCoder 2nd Anniversary Palace
- BestCoder 2nd Anniversary HDU5720
- HDU 5718 BestCoder 2nd Anniversary Oracle (模拟)
- ACM集训day5
- 消除游戏解析
- HTML5 Video Events and API
- HDU 5100 Chessboard
- 定义颜色color时6位或8位值的区别
- BestCoder 2nd Anniversary 1001/hdu5718 Oracle
- 0713
- HDU 5720 Wool
- MAC下如何更改Mysql的密码
- dataTransfer 对象
- 关于Android的assets资源使用,以及网络间的数据传递JSON格式处理
- 更改mysql ini 拒绝访问
- 定时器的合并和变速
- HDU 5721 Palace