找到最小的非零数字拆开来相加。

高精度。

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define LL long long
char s[];
int a[],b[];
int t,p;
int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%s",s);
int len=strlen(s);
p=;
if(len==)//只有一个数字,不符合
{
puts("Uncertain"); continue;
}
for(int i=;i<len;i++)
{
a[i]=s[i]-'';
if(a[i]!=) p++;
}
if(p<=)//非零数字不足两个,不符合
{
puts("Uncertain"); continue;
}
sort(a,a+len);
for(int i=;i<len;i++)//找到最小的非零数字
{
if(a[i]!=)
{
p=i; break;
}
}
int j=;
for(int i=;i<len;i++)
{
if(i==p) continue;
b[j++]=a[i];
}
b[]+=a[p];//相加
b[j]=;
for(int i=;i<j;i++)//高精度进位
{
if(b[i]<) break;
b[i+]+=b[i]/;
b[i]%=;
}
if(b[j]>) j++;
for(int i=j-;i>=;i--)
printf("%d",b[i]);
puts("");
}
}

BestCoder 2nd Anniversary 1001 Oracle的更多相关文章

  1. BestCoder 2nd Anniversary的前两题

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

  2. BestCoder 2nd Anniversary

    A题 Oracle http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=703&pid=1001 大数相加: ...

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

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

  4. hdu 5719 BestCoder 2nd Anniversary B Arrange 简单计数问题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5719 题意:一个数列为1~N的排列,给定mn[1...n]和mx[1...n],问有符合的排列数为多少 ...

  5. hdu 5720 BestCoder 2nd Anniversary Wool 推理+一维区间的并

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5720 题意:有n(n <= 105)个数 ,每个数小于等于 1018:问在给定的[L,R]区间中 ...

  6. BestCoder 2nd Anniversary 1002 Arrange

    排除所有不符合条件后根据当前位置上下界计算, 由于前面取的数肯定在之后的区间内,所以去掉已取的个数即可. #include <iostream> #include <cstdio&g ...

  7. BestCoder 2nd Anniversary/HDU 5719 姿势

    Arrange Accepts: 221 Submissions: 1401 Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 262144/2 ...

  8. 贪心 BestCoder Round #39 1001 Delete

    题目传送门 /* 贪心水题:找出出现次数>1的次数和res,如果要减去的比res小,那么总的不同的数字tot不会少: 否则再在tot里减去多余的即为答案 用set容器也可以做,思路一样 */ # ...

  9. 二分图点染色 BestCoder 1st Anniversary($) 1004 Bipartite Graph

    题目传送门 /* 二分图点染色:这题就是将点分成两个集合就可以了,点染色用dfs做, 剩下的点放到点少的集合里去 官方解答:首先二分图可以分成两类点X和Y, 完全二分图的边数就是|X|*|Y|.我们的 ...

随机推荐

  1. KVC与KVO的理解

    KVC与KVO是Objective C的关键概念. Key—Value Coding (KVC) 即是指NSKeyValueCoding,一个非正式的Protocol,提供一种机制间接访问对象的属性. ...

  2. Struts2 标签库详解2

    Struts2标签库 包括: OGNL Struts2标签分类 控制标签 :(if, elseif,else, iterator, append, merge, generator, subset, ...

  3. Linux中Firefox——Httpfox插件安装及使用

    Httpfox插件安装步骤: 1.打开firefox浏览器,点击左上方"工具"中的"附加组件" 2.在弹出页中搜索"Httpfox",点击下 ...

  4. 视差滚动(Parallax Scrolling)效果的原理和实现

    视差滚动(Parallax Scrolling)是指让多层背景以不同的速度移动,形成立体的运动效果,带来非常出色的视觉体验.作为今年网页设计的热点趋势,越来越多的网站应用了这项技术. 一.什么是视差滚 ...

  5. 解决mac ssh连linux中文乱码的问题[转]

    将Mac下/etc/ssh_config中的SendEnv LANG LC_*这一行用#号注释掉 reference: http://www.zhihu.com/question/20117388

  6. [C++程序设计]引用

    对一个数据可以使用“引用”(reference),这是C++对C的一个重要扩充,引用是一种新的变量类型,它的作用是为一个变量起一个别名.假如有一个变量a,想给它起一个别名b,可以这样写:int a; ...

  7. MVC4商城项目三:分部视图在导航条上的应用

    写了几天发觉大部分时间用在JS上了,本来想写个musicstore,却加了框架,然后又想用后台,然后又想用上bootstrapt,然后又想弄权限设计,然后又想………… 看来是想多了~ 好吧,最近把后台 ...

  8. Oracle select 中case 的使用以及使用decode替换case

    表结构如下: 将money<50的显示为贫农,money<80的显示为中农,其他的显示为富农,sql 语句如下 select name, case then '贫农' then '中农' ...

  9. LeetCode_Interleaving String

    Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. For example, Given: s1 ...

  10. QML的渲染方式相较于之前的版本也有了重大的更新(CPU线程负责绘制,GPU线程负责渲染),还有好多经常评论 good

    作者:qyvlik链接:http://www.zhihu.com/question/38867614/answer/78583440来源:知乎著作权归作者所有,转载请联系作者获得授权. 做UI啊.如果 ...