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

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 \le T \le 10) $, which denotes the number of test cases.

For each test case, the single line contains an integer $ n $ $ (1 \le 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

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<cstdio>
#include<iostream>
#include<cstring>
#include<stdlib.h>
#include<algorithm>
using namespace std;
#define N 10000005
char s[N];
int main()
{
int T,len,minn,mi,i;
scanf("%d",&T);
while(T--)
{
scanf("%s",&s);
len=strlen(s);
sort(s,s+len);
if(len==||s[len-]=='')
printf("Uncertain\n");
else
{
for( i=;i<len;i++)
if(s[i]!='')
{
minn=i;
mi=s[i]-'';
break;
}
for(i=minn;i>;i--)
s[i]=s[i-];//接下来都是从1开始
s[]+=mi;
for(i=;i<len-;i++)
{
if(s[i]>'')
{
s[i+]++;
s[i]-=;
}
else
break;
}
printf("%d",s[len-]-'');
for(i=len-;i>=;i--)
printf("%c",s[i]);
printf("\n");
}
}
return ;
}

HDU 5718 Oracle(高精度)的更多相关文章

  1. hdu 5718 Oracle 高精度

    Oracle Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Problem ...

  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. bzoj3504: [Cqoi2014]危桥 网络流

    一种网络流建图的思路吧,改天最好整理一波网络流建图思路 #include <bits/stdc++.h> using namespace std; int n,h,t,a1,a2,an,b ...

  2. Unity3D 浏览工具

    键盘控制: 1.键盘箭头:先选中场景激活场景 按箭头前后左右  shift +箭头 加速移动 2.使物体成为场景焦点:左侧层次视图列表选中物体,移动鼠标指针到场景视图上 按F,选中物体成为场景视图中心 ...

  3. 仿qq的侧拉菜单效果

    自定义控件 import android.animation.ArgbEvaluator; import android.animation.FloatEvaluator; import androi ...

  4. angularjs的懒加载

    1.angularJS懒加载依赖模块 //设置 .config [ '$ocLazyLoadProvider' ($ocLazyLoadProvider) -> # We configure o ...

  5. B树、B-树、B+树、B*树详解

    注:本文为个人学习摘录,原文地址:http://www.blogjava.net/supercrsky/articles/185167.html B树 即二叉搜索树: 1.所有非叶子结点至多拥有两个儿 ...

  6. gamma

    图:显卡(驱动程序)上的Gamma设置 图:ACDSEE中的曝光调节 二. 什么是Gamma? 2.1. 显示器Gamma曲线 Gamma可能源于CRT(显示器/电视机)的响应曲线,即其亮度与输入电压 ...

  7. web.xml讲解

    <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE web-app PUBLIC "- ...

  8. HTML form的一些属性(第一版)

    p,li { white-space: pre-wrap } HTML表单属性总结(第一版) 基本格式为:<input type="类型" name="名字[唯一, ...

  9. shell中bash的常见命令

    shell 在计算机科学中,Shell俗称壳,用来区别Kernel(核) Shell分类:1:图形界面shell:通过提供友好的可视化界面,调用相应应用程序,如windows系列操作系统,Linux系 ...

  10. 在MacOS下Python安装lxml报错xmlversion.h not found 报错的解决方案

    最近在看一个自动化测试框架的问题,需要用到Lxml库,下载lxml总是报错. 1,使用pip安装lxml pip install lxml 2,然后报错了,报错内容是: In file include ...