hdu-5718 Oracle(水题)
题目链接:
Oracle
Time Limit: 8000/4000 MS (Java/Others)
Memory Limit: 262144/262144 K (Java/Others)
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 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`.
For each test case, the single line contains an integer n (1≤n<10^10000000).
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath> using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss)); typedef long long LL; template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
if(!p) { puts("0"); return; }
while(p) stk[++ tp] = p%10, p/=10;
while(tp) putchar(stk[tp--] + '0');
putchar('\n');
} const LL mod=1e9+7;
const double PI=acos(-1.0);
const int inf=1e9;
const int N=1e7+10;
const int maxn=1e3+10;
const double eps=1e-6; char s[N];
int flag[11],ans[N]; int main()
{ int t;
read(t);
while(t--)
{
mst(flag,0);
scanf("%s",s);
int len=strlen(s),num=0;
For(i,0,len-1)if(s[i]=='0')num++;
if(num==len-1)cout<<"Uncertain\n";
else
{
int mmin=9;
For(i,0,len-1)flag[s[i]-'0']++;
For(i,1,9)
{
if(flag[i]){flag[i]--,mmin=i;break;}
}
int cnt=0;
for(int i=0;i<=9;i++)
while(flag[i]--)ans[++cnt]=i;
ans[1]+=mmin;
ans[len]=0;
for(int i=1;i<=len-1;i++)
{
ans[i+1]+=ans[i]/10;
ans[i]=ans[i]%10;
}
if(ans[len])printf("%d",ans[len]);
for(int i=len-1;i>0;i--)printf("%d",ans[i]);
printf("\n");
}
}
return 0;
}
最新文章
- Linux yum如何下载rpm包到本地
- LINQ to XML 编程基础
- 日期的js插件DatePicker
- hdu 4756 MST+树形dp ****
- QTP
- codeforces 577B B. Modulo Sum(水题)
- Windows下安装Redmine
- iOS - Sign up/in 注册/登录
- hdu1358 Period
- Java日期时间使用总结
- rsync 实现实时增量备份
- Ax 从一个form关闭另外一个form,AX全局变量
- 关于进程间通信的总结(IPC)
- [OFBiz]简介 一
- OpenGL红宝书例子2.2 uniform变量的使用
- python之路——23
- js一行代码解决各种IE兼容问题
- bzoj2588 Spoj10628. count on a tree
- 字符串匹配--AC自动机模板
- css动画和jq动画的简单区分
热门文章
- App后台运行通知函数
- LeetCode OJ--Valid Palindrome
- 自定义table样式
- Java中ArrayList类
- 洛谷 P2831 愤怒的小鸟
- go语言学习之路 一:开发环境配置
- Linux服务器同步网络时间
- [Cypress] install, configure, and script Cypress for JavaScript web applications -- part3
- MySQL中insert ignore into, on duplicate key update,replace into,insert … select … where not exist的一些用法总结
- 常用DOS下MSC指令