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<1010000000).

 
Output
For each test case, print a positive integer or a string `Uncertain`.
 
Sample Input
3
112
233
1
 
Sample Output
22
35
Uncertain

Hint

In the first example, it is optimal to split $ 112 $ into $ 21 $ and $ 1 $, and their sum is $ 21 + 1 = 22 $.

In the second example, it is optimal to split $ 233 $ into $ 2 $ and $ 33 $, and their sum is $ 2 + 33 = 35 $.

In the third example, it is impossible to split single digit $ 1 $ into two parts.

思路:简单高精度;
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
using namespace std;
#define ll __int64
#define mod 100000007
#define esp 0.00000000001
const int N=1e5+,M=1e7+,inf=1e9+;
char a[M];
char b[M];
char c[M];
void add(char a[],char b[])//a=a+b
{
int i,j,k,sum=;
k=strlen(a)>strlen(b)?strlen(a):strlen(b);
a[k+]=;
for(i=strlen(a)-,j=strlen(b)-;i>=||j>=;i--,j--,k--)
{ if(i>=) sum+=a[i]-''; if(j>=) sum+=b[j]-'';
a[k]=sum%+''; sum/=;
}
if(sum) a[]=sum+'';
else strcpy(a,&a[]);
printf("%s\n",a);
}
int check(char *a)
{
int x=strlen(a);
if(x==)
return ;
for(int i=;i<x;i++)
if(a[i]!='')
return ;
return ;
}
int flag[];
int main()
{
int x,y,z,i,t;
int T;
scanf("%d",&T);
while(T--)
{
memset(flag,,sizeof(flag));
scanf("%s",a);
x=strlen(a);
for(i=;i<x;i++)
flag[a[i]-'']++;
int ji=;
int lu=;
for(i=;i<=;i++)
if(flag[i])
{
c[lu++]=''+i;
flag[i]--;
break;
}
for(i=;i>=;i--)
{
while(flag[i]!=)
{
b[ji++]=i+'';
flag[i]--;
}
}
b[ji]='\0';
c[lu]='\0';
if(check(b)&&check(c))
add(b,c);
else
printf("Uncertain\n");
}
return ;
}

hdu 5718 Oracle 高精度的更多相关文章

  1. HDU 5718 Oracle(高精度)

    Time Limit:4000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Description There ...

  2. hdu 5718(Oracle)大数加法

    曾经有一位国王,统治着一片未名之地.他膝下有三个女儿. 三个女儿中最年轻漂亮的当属Psyche.她的父亲不确定她未来的命运,于是他来到Delphi神庙求神谕. 神谕可以看作一个不含前导零的正整数n n ...

  3. HDU 5718 Oracle

    如果非零的数小于等于1个,则无解.否则有解. 取出一个最小的非零的数作为一个数,剩下的作为一个数,相加即可. #include<cstdio> #include<cstring> ...

  4. BestCoder 2nd Anniversary/HDU 5718 高精度 模拟

    Oracle Accepts: 599 Submissions: 2576 Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 262144/26 ...

  5. Hdu 5568 sequence2 高精度 dp

    sequence2 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=556 ...

  6. hdu 1042 N!(高精度乘法 + 缩进)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1042 题目大意:求n!, n 的上限是10000. 解题思路:高精度乘法 , 因为数据量比较大, 所以 ...

  7. HDU 4704 Sum (高精度+快速幂+费马小定理+二项式定理)

    Sum Time Limit:1000MS     Memory Limit:131072KB     64bit IO Format:%I64d & %I64u Submit Status  ...

  8. hdu 1042 N!(高精度乘法)

    Problem Description Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N!   Input One N in ...

  9. HDU 5047 Sawtooth 高精度

    题意: 给出一个\(n(0 \leq n \leq 10^{12})\),问\(n\)个\(M\)形的折线最多可以把平面分成几部分. 分析: 很容易猜出来这种公式一定的关于\(n\)的一个二次多项式. ...

随机推荐

  1. 一个包的net到gs流程

    再来看看一个包走共享内存的流程 先来看看net进程这块如何处理的 {//用shareData这种类型封装刚才从无锁队列中取到的包 shareData sd; sd.channel_id = pkt.c ...

  2. jquery 常用组件的小代码

    获得所有复选框的值 function getAllValue() { var str=""; $("input[name='checkbox']:checkbox&quo ...

  3. POJ 3258 River Hopscotch (binarysearch)

    River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5193 Accepted: 2260 Descr ...

  4. Map:比较新增加日期的和需要删除的日期 使用方法

    1.场景描述:根据在日历选择的日期,数据库来保持我们选择日期. 2.方法,硬删除的方法,每次全部删除,然后再重新添加选择的新的日期.这样导致如果需要保存create_time的情况,那么每次操作的都是 ...

  5. Win8必知快捷键汇总

    * Win+C:调出应用Charm菜单(开始界面.传统桌面) * Win+D:所有程序最小化,再次按下恢复(开始界面.传统桌面) * Win+E:打开我的电脑(开始界面.传统桌面) * Win+F:调 ...

  6. oracle impdp的table_exists_action详解

    oracle impdp的table_exists_action详解 分类: [oracle]--[备份与恢复]2012-01-06 22:44 9105人阅读 评论(0) 收藏 举报 tableac ...

  7. Java 延时常见的几种方法

    1. 用Thread就不会iu无法终止 new Thread(new Runnable() { public void run() { while (true) { test(); try { Thr ...

  8. Flatty Shadow在线为Icon图标生成长阴影效果。

    Flatty Shadow在线为Icon图标生成长阴影效果. Flatty Shadow 彩蛋爆料直击现场 Flatty Shadow在线为Icon图标生成长阴影效果.

  9. 深入浅出ES6(十):集合

    作者 Jason Orendorff  github主页  https://github.com/jorendorff 前段时间,官方名为“ECMA-262,第六版,ECMAScript 2015语言 ...

  10. Codeforces Round #258 (Div. 2)(A,B,C,D)

    题目链接 A. Game With Sticks time limit per test:1 secondmemory limit per test:256 megabytesinput:standa ...