HDU 5718 Oracle(高精度)

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.

从给出的数中挑一个非零最小数出来,主要是高精度的处理

 1 #include<cstdio>
 2 #include<iostream>
 3 #include<cstring>
 4 #include<stdlib.h>
 5 #include<algorithm>
 6 using namespace std;
 7 #define N 10000005
 8 char s[N];
 9 int main()
10 {
11     int T,len,minn,mi,i;
12     scanf("%d",&T);
13     while(T--)
14     {
15         scanf("%s",&s);
16         len=strlen(s);
17         sort(s,s+len);
18         if(len==1||s[len-2]==‘0‘)
19             printf("Uncertain\n");
20         else
21         {
22             for( i=0;i<len;i++)
23                 if(s[i]!=‘0‘)
24                 {
25                     minn=i;
26                     mi=s[i]-‘0‘;
27                     break;
28                 }
29             for(i=minn;i>0;i--)
30                 s[i]=s[i-1];//接下来都是从1开始
31             s[1]+=mi;
32             for(i=1;i<len-1;i++)
33             {
34                 if(s[i]>‘9‘)
35                 {
36                     s[i+1]++;
37                     s[i]-=10;
38                 }
39                 else
40                     break;
41             }
42             printf("%d",s[len-1]-‘0‘);
43             for(i=len-2;i>=1;i--)
44                 printf("%c",s[i]);
45             printf("\n");
46         }
47     }
48     return 0;
49 }
时间: 2024-11-07 07:52:44

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

hdu 5718 Oracle 高精度

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 beautifu

HDU 5718 Oracle

Oracle Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 122    Accepted Submission(s): 53 Problem Description There is once a king and queen, rulers of an unnamed city, who have three daughters

hdu 5718(Oracle)大数加法

曾经有一位国王,统治着一片未名之地.他膝下有三个女儿. 三个女儿中最年轻漂亮的当属Psyche.她的父亲不确定她未来的命运,于是他来到Delphi神庙求神谕. 神谕可以看作一个不含前导零的正整数n n n. 为了得到真正的预言,他可以将n n n的各个数位重新排列,并将其分成两个不含前导零的正整数. 请你帮助他求出这两个正整数最大的和.如果不存在这样的两个正整数,输出"Uncertain". 用getchar可以一个数字一个地读入,对于一个十进制数,最多就是10个数字,使用计数可以很方

hdu 1063 Exponentiation (高精度小数乘法)

//大数继续,额,要吐了. Problem Description Problems involving the computation of exact values of very large magnitude and precision are common. For example, the computation of the national debt is a taxing experience for many computer systems. This problem re

HDU 6206 Apple ( 高精度 &amp;&amp; 计算几何 &amp;&amp; 三点构圆求圆心半径 )

题意 : 给出四个点,问你第四个点是否在前三个点构成的圆内,若在圆外输出"Accepted",否则输出"Rejected",题目保证前三个点不在一条直线上. 分析 : 简单的计算几何问题,如果能够知道圆心和半径(Radius)以及第四个点和圆心的距离(Distance),我们就能够判断第四个点是否在圆外,例如Distance > Radius则在圆外.三点构圆 的圆心和半径是能够推导出公式的 (参考==> http://blog.csdn.net/dea

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

Sum Time Limit:1000MS     Memory Limit:131072KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 4704 Description Sample Input 2 Sample Output 2 Hint 1. For N = 2, S(1) = S(2) = 1. 2. The input file consists of multiple test cases. 题意:给定一

HDU 1042 N! 高精度乘法

Problem Description Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N! Input One N in one line, process to the end of file. Output For each N, output N! in one line. Sample Input 1 2 3 Sample Output 1 2 6 题目意思很简单,就是让你求N的阶乘,但是N的范围有10000,所

Hdu 1042 N! (高精度数)

Problem Description Givenan integer N(0 ≤ N ≤ 10000), your task is to calculate N! Input OneN in one line, process to the end of file. Output Foreach N, output N! in one line. Sample Input 1 2 3 Sample Output 1 2 6 Author JGShining(极光炫影) /********* 高

HDU1402 FFT高精度乘法模板题

#include<bits/stdc++.h> using namespace std; //HDU 1402 求高精度乘法 const double PI = acos(-1.0); //复数结构体 struct Complex { double x,y;//实部和虚部x+yi Complex(double _x = 0.0,double _y = 0.0) { x = _x; y = _y; } Complex operator -(const Complex &b)const {