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. Mrt render

    mutil render target Pixel shder输出一个结构体 Out.f4Color Out.f4Normal 这步在渲染物体的shader里 在application setcolo ...

  2. HDOJ 3486 Interviewe

    人生中第一次写RMQ....一看就知道 RMQ+2分但是题目文不对题....不知道到底在问什么东西....各种WA,TLE,,RE...后就过了果然无论错成什么样都可以过的,就是 上层的样例 啊  I ...

  3. 去“IOE”

    所谓去“IOE”,是对去“IBM.Oracle.EMC”的简称,三者均为海外IT巨头,其中IBM代表硬件以及整体解决方案服务商,Oracle代表数据库,EMC代表数据存储.去“IOE”策略更广泛的理解 ...

  4. ab压力测试工具-批量压测脚本

    ab(Apache benchmark)是一款常用的压力测试工具.简单易用,ab的命令行一次只能支持一次测试.如果想要批量执行不同的测试方式,并自动对指标进行分析,那么单靠手工一条一条命令运行ab,估 ...

  5. GCD使用小结

    - ( * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{         NSLog(; i < ; i ++) {         [self o ...

  6. Android ListVIew 详解(一)

    在android开发中ListView是比较常用的组件,它以列表的形式展示具体内容,并且能够根据数据的长度自适应显示.抽空把对ListView的使用做了整理,并写了个小例子,如下图. 列表的显示需要三 ...

  7. 深入浅出ES6(十五):子类 Subclassing

    作者 Jason Orendorff  github主页  https://github.com/jorendorff 在之前的文章<深入浅出ES6(十三):类 Class>中,我们一起深 ...

  8. java 如何连接MySql数据库

    利用jdbc方式连接数据库. 1.添加mysql驱动jar包 我用的是这个驱动包mysql-connector-java-5.1.26-bin.jar 添加方式: 2.加载MySql驱动类 priva ...

  9. Linux之select系统调用_2

    在上一篇博文中,我们的程序中我们有3个客户端,因此也事先建立了3个管道,每个客户端分别使用一个管道向服务器发送消息.而在服务器端使用select系统调用,只要监测到某一管道有消息写入,服务器就将其re ...

  10. nodejs的require模块及路径

    在nodejs中,模块大概可以分为核心模块和文件模块. 核心模块是被编译成二进制代码,引用的时候只需require表示符即可,如(require('net')). 文件模块,则是指js文件.json文 ...