hdu 4068 I-number【大数】
题目:
I-numberTime Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Problem Description
The I-number of x is defined to be an integer y, which satisfied the the conditions below:
1. y>x; 2. the sum of each digit of y(under base 10) is the multiple of 10; 3. among all integers that satisfy the two conditions above, y shouble be the minimum. Given x, you're required to calculate the I-number of x.
Input
An integer T(T≤100) will exist in the first line of input, indicating the number of test cases.
The following T lines describe all the queries, each with a positive integer x. The length of x will not exceed 105.
Output
Output the I-number of x for each query.
Sample Input
Sample Output
Source
Recommend
liuyiding
|
题意:
算法:
思路:
code:
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std; const int maxn = 200000;
int a[maxn];
char str[maxn];
int len; void add()
{
int c = 1;
for(int i = 0;; i++)
{
int tmp = a[i]+c;
a[i] = tmp%10;
c = tmp/10;
if(c == 0) break; //加到没有进位
}
if(a[len] != 0) len++; //加到头有进位
} bool judge()
{
int sum = 0;
for(int i = 0; i < len; i++)
sum += a[i];
return sum%10;
} int main()
{
int T;
scanf("%d", &T);
while(T--)
{
scanf("%s", str);
len = strlen(str); memset(a,0,sizeof(a)); //不能少否则会WA,前面的组a[len]可能会有价
int j = len;
for(int i = 0; i < len; i++) a[i] = str[--j]-'0';
add();
while(judge()) add(); for(int i = len-1; i >= 0; i--) printf("%d",a[i]);
printf("\n");
}
return 0;
}
#include<stdio.h>
#include<string.h> const int maxn = 200000;
int a[maxn];
char str[maxn];
int len; void add()
{
int c = 1;
for(int i = 0; i < len; i++)
{
int tmp = a[i]+c;
a[i] = tmp%10;
c = tmp/10;
if(c == 0) return;
}
a[len] = c; len++;
return;
} int judge()
{
int sum = 0;
for(int i = 0; i < len; i++)
{
sum += a[i];
}
return sum%10;
}
int main()
{
int T;
scanf("%d", &T);
while(T--)
{
scanf("%s", str);
len = strlen(str); int j = len;
for(int i = 0; i < len; i++) a[i] = str[--j]-'0';
add();
while(judge()) add(); for(int i = len-1; i >= 0; i--) printf("%d", a[i]);
printf("\n");
}
}
hdu 4068 I-number【大数】的更多相关文章
- HDU 1212 Big Number 大数模小数
http://acm.hdu.edu.cn/showproblem.php?pid=1212 题目大意: 给你一个长度不超过1000的大数A,还有一个不超过100000的B,让你快速求A % B. 什 ...
- hdu 5898 odd-even number 数位DP
传送门:hdu 5898 odd-even number 思路:数位DP,套着数位DP的模板搞一发就可以了不过要注意前导0的处理,dp[pos][pre][status][ze] pos:当前处理的位 ...
- hdu 2665 Kth number
划分树 /* HDU 2665 Kth number 划分树 */ #include<stdio.h> #include<iostream> #include<strin ...
- hdu 4670 Cube number on a tree(点分治)
Cube number on a tree Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/ ...
- 主席树[可持久化线段树](hdu 2665 Kth number、SP 10628 Count on a tree、ZOJ 2112 Dynamic Rankings、codeforces 813E Army Creation、codeforces960F:Pathwalks )
在今天三黑(恶意评分刷上去的那种)两紫的智推中,突然出现了P3834 [模板]可持久化线段树 1(主席树)就突然有了不详的预感2333 果然...然后我gg了!被大佬虐了! hdu 2665 Kth ...
- HDU - 1711 A - Number Sequence(kmp
HDU - 1711 A - Number Sequence Given two sequences of numbers : a[1], a[2], ...... , a[N], and b[1 ...
- HDU 1212 Big Number(C++ 大数取模)(java 大数类运用)
Big Number 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1212 ——每天在线,欢迎留言谈论. 题目大意: 给你两个数 n1,n2.其中n1 ...
- 题解报告:hdu 1212 Big Number(大数取模+同余定理)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1212 Problem Description As we know, Big Number is al ...
- hdu 1212 Big Number(大数取模)
Problem Description As we know, Big Number is always troublesome. But it's really important in our A ...
随机推荐
- 搜索引擎Solr-6.6.0搭建
一.简介 Solr是一个独立的企业级搜索应用服务器,它对外提供类似于Web-service的API接口.用户可以通过http请求,向搜索引擎服务器提交一定格式的XML文件,生成索引:也可以通过Http ...
- 【Hadoop】Hadoop MR Job工作流引擎
Apache Oozie 是用于 Hadoop 平台的一种工作流调度引擎.该框架(如图 1 所示)使用 Oozie 协调器促进了相互依赖的重复工作之间的协调,您可以使用预定的时间或数据可用性来触发 A ...
- Exception thrown in catch and finally clause
Based on reading your answer and seeing how you likely came up with it, I believe you think an " ...
- 转: NetBean 远程开发的好文2 --> 工欲善其事,必先利其器系列--Netbeans之远程开发
转自: http://www.cnblogs.com/zuoca/archive/2012/07/09/Remote_Development_With_Netbeans_origin.html 实践 ...
- Java中的回调函数学习-深入浅出
Java中的回调函数一般来说分为下面几步: 声明回调函数的统一接口interface A.包括方法callback(); 在调用类caller内将该接口设置为私有成员private A XXX; 在c ...
- JAVA经常使用集合框架使用方法具体解释基础篇二之Colletion子接口List
接着上一篇,接着讲讲集合的知识.上一篇讲了Collection接口.它能够说是集合的祖先了,我们这一篇就说说它的子孙们. 一.Collection的子接口 List:有序(存入和取出的顺序一致).元素 ...
- java 页面错误转发提示页面 errorPage转跳报HTTP500内部服务器错误
errorPage和isErrorPage本来是很简单的功能,但是我却没弄出来,还百度了半天,结果发现是IE的设置问题.将下图中的“Show friendly HTTP error messages( ...
- 在服务端发起一个Post请求
1.http://www.tuling123.com/openapi/api?key=9d2ff29d44b54e55acadbf5643569584&info=? 上面这个请求在服务端发起 ...
- MATLAB squeeze 函数
squeeze 除去size为1的维度 B = squeeze(A) 描述: B = squeeze(A),B与A有相同的元素,但所有只有一行或一列的维度(a singleton dimension ...
- IBM Rational Appscan使用之扫描结果分析
转自:http://www.nxadmin.com/penetration/825.html 之前有IBM Rational Appscan使用详细说明的一篇文章,主要是针对扫描过程中配置设置等.本文 ...