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 ...
随机推荐
- netty handle处理流程
server handlerAdded server channelRegistered server channelActive server read server channelInactive ...
- 使用Spring开发和监控线程池服务
第1步:添加maven 项目 第2步:添加依赖库 将Spring的依赖添加到Maven的pom.xml文件中. 1 2 3 4 5 6 7 8 9 10 11 <!-- Spring 3 dep ...
- java 实体序列化的意义
一.序列化的意义 客户端访问了某个能开启会话功能的资源, web服务器就会创建一个与该客户端对应的HttpSession对象,每个HttpSession对象都要站用一定的内存空间.如果在某一时间段内访 ...
- Android学习(七) Android实现计算器
前台页面代码,通过线性布局方式实现计算器页面:如图所示 color.xml,自定义颜色values: <?xml version="1.0" encoding="u ...
- rabbitmq 用户和授权
官方文档 https://my.oschina.net/hncscwc/blog/262246?p=
- (九)Thymeleaf用法——Themeleaf注释
4. 注释 模板名称:comment.html 4.1 标准 HTML/XML注释 语法:<!-- --> 4.2 解析器级注释块(Parser-level ...
- java ee xml 学习
该文章对j2ee的xml各种标签做了详细全面的说明 http://01121264-163-com.iteye.com/blog/1530063
- java中poi解析excel(兼容07版本以上及以下:.xls和.xlsx格式)
package com.genersoft.cbms.ysbz.ExcelDr.cmd; import com.genersoft.cbms.ysbz.ExcelDr.dao.ExcelDrDao; ...
- ar命令提取.o的时候报错:is a fat file (use libtool(1) or lipo(1) and ar(1) on it)
在解压.a文件的时候,报错:s a fat file (use libtool(1) or lipo(1) and ar(1) on it),原因是该.a文件包含了多个cpu架构,比如armv7,ar ...
- PHP面试题及答案解析(5)—数据结构与算法
1.使对象可以像数组一样进行foreach循环,要求属性必须是私有.(Iterator模式的PHP5实现,写一类实现Iterator接口) <?php class Test implements ...