BestCoder 2nd Anniversary 1001 Oracle
找到最小的非零数字拆开来相加。
高精度。
#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的更多相关文章
- BestCoder 2nd Anniversary的前两题
Oracle Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Su ...
- BestCoder 2nd Anniversary
A题 Oracle http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=703&pid=1001 大数相加: ...
- BestCoder 2nd Anniversary/HDU 5718 高精度 模拟
Oracle Accepts: 599 Submissions: 2576 Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 262144/26 ...
- hdu 5719 BestCoder 2nd Anniversary B Arrange 简单计数问题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5719 题意:一个数列为1~N的排列,给定mn[1...n]和mx[1...n],问有符合的排列数为多少 ...
- hdu 5720 BestCoder 2nd Anniversary Wool 推理+一维区间的并
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5720 题意:有n(n <= 105)个数 ,每个数小于等于 1018:问在给定的[L,R]区间中 ...
- BestCoder 2nd Anniversary 1002 Arrange
排除所有不符合条件后根据当前位置上下界计算, 由于前面取的数肯定在之后的区间内,所以去掉已取的个数即可. #include <iostream> #include <cstdio&g ...
- BestCoder 2nd Anniversary/HDU 5719 姿势
Arrange Accepts: 221 Submissions: 1401 Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 262144/2 ...
- 贪心 BestCoder Round #39 1001 Delete
题目传送门 /* 贪心水题:找出出现次数>1的次数和res,如果要减去的比res小,那么总的不同的数字tot不会少: 否则再在tot里减去多余的即为答案 用set容器也可以做,思路一样 */ # ...
- 二分图点染色 BestCoder 1st Anniversary($) 1004 Bipartite Graph
题目传送门 /* 二分图点染色:这题就是将点分成两个集合就可以了,点染色用dfs做, 剩下的点放到点少的集合里去 官方解答:首先二分图可以分成两类点X和Y, 完全二分图的边数就是|X|*|Y|.我们的 ...
随机推荐
- iOS 关于tableView中有多个textField,输入框被遮住的解决方法
这里采用tableView整体上移的方法. 代码:(其中 60 为 单元格的高度) //点击输入框触发 - (void)textFieldDidBeginEditing:(UITextField *) ...
- SPOJ 4206 Fast Maximum Matching (二分图最大匹配 Hopcroft-Carp 算法 模板)
题目大意: 有n1头公牛和n2头母牛,给出公母之间的m对配对关系,求最大匹配数.数据范围: 1 <= n1, n2 <= 50000, m <= 150000 算法讨论: 第一反应 ...
- (转) 学习C++ -> 引用( References )
学习C++ -> 引用( References ) 一.引用的介绍 引用就是某一变量(目标)的一个别名, 相当于同一个人有了两个名字, 无论喊哪一个名字实际上都是指的同一个人. 同样, 在 ...
- mysql 复习与学习(二)数据库及表结构的创建删除
mysql -h localhost -uroot -p123456 //连接数据库 show databases; //查看数据库 create database if not exists db_ ...
- jquery.ajax和Ajax 获取数据
前几天接触了jquery 看到里面ajax的部分,自己也不是很懂,然后有重复看了即便,然后写了一个小功能,分享下...我刚学的.有错误的请指教. 验证用户名是否存在 在checkname_jqajax ...
- Scrapy学习系列(一):网页元素查询CSS Selector和XPath Selector
这篇文章主要介绍创建一个简单的spider,顺便介绍一下对网页元素的选取方式(css selector, xpath selector). 第一步:创建spider工程 打开命令行运行以下命令: sc ...
- UML中九种图的理解
1.用例图. 用例图是用来描述用户需求的,从用户的角度来描述系统的功能,并指出各个执行者.强调谁在使用,系统的执行者是谁. 2.类图. 用来定义系统中的类,包括描述类的结构和类之间的关系.类图的主要作 ...
- SSE2 Intrinsics各函数介绍[转]
SIMD相关头文件包括: //#include <ivec.h>//MMX //#include <fvec.h>//SSE(also include ivec.h) //#i ...
- zend framework 初识
1. 请求顺序 : index.php --> Bootstrap.php --> IndexController.php 2. 验证顺序 : Bootstrap.php function ...
- Cleaning Shifts(POJ 2376 贪心)
Cleaning Shifts Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 15143 Accepted: 3875 ...