题目链接:

Oracle

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 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 integer n (1≤n<10^10000000).

 
Output
For each test case, print a positive integer or a string `Uncertain`.
 
Sample Input
3
112
233
1
 
Sample Output
22
35
Uncertain
 
题意:
 
给一个大数,拆成两个没有前导0的数,使其和最大;
 
思路:
 
贪心,可知应该把大于0的最小数当做单独的那一个数,这样才能保证最大;然后就是一个大数加法;
 
AC代码:
 
#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;
}

  

最新文章

  1. Linux yum如何下载rpm包到本地
  2. LINQ to XML 编程基础
  3. 日期的js插件DatePicker
  4. hdu 4756 MST+树形dp ****
  5. QTP
  6. codeforces 577B B. Modulo Sum(水题)
  7. Windows下安装Redmine
  8. iOS - Sign up/in 注册/登录
  9. hdu1358 Period
  10. Java日期时间使用总结
  11. rsync 实现实时增量备份
  12. Ax 从一个form关闭另外一个form,AX全局变量
  13. 关于进程间通信的总结(IPC)
  14. [OFBiz]简介 一
  15. OpenGL红宝书例子2.2 uniform变量的使用
  16. python之路——23
  17. js一行代码解决各种IE兼容问题
  18. bzoj2588 Spoj10628. count on a tree
  19. 字符串匹配--AC自动机模板
  20. css动画和jq动画的简单区分

热门文章

  1. App后台运行通知函数
  2. LeetCode OJ--Valid Palindrome
  3. 自定义table样式
  4. Java中ArrayList类
  5. 洛谷 P2831 愤怒的小鸟
  6. go语言学习之路 一:开发环境配置
  7. Linux服务器同步网络时间
  8. [Cypress] install, configure, and script Cypress for JavaScript web applications -- part3
  9. MySQL中insert ignore into, on duplicate key update,replace into,insert … select … where not exist的一些用法总结
  10. 常用DOS下MSC指令