题目:



I-number

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 1006    Accepted Submission(s): 398

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
1
202
 
Sample Output
208
 
Source
 
Recommend
liuyiding
 

题意:


第一个数 T 代表测试数据组数

每组给你一个大数 N (N的长度 <= 100000)

求最小的 > N 且满足每一位相加的总和能够整除 10 的数


算法:


大数相加,只是+1比较简单,随便模拟一下就好了

思路:


不断的 + 1 直到满足情况
官方题解中也说的是最多+20个 1 就可以求出

昨天白天比赛的时候是 浩神 AC 的,KB 神也和我说了下怎么做, 白天看了下 浩神的代码,自己写,还是要 WA
昨晚比赛时按照浩神的思路纠结出了 AC的代码
刚刚问了下 KB 神,原来是掉了个初始化,改了也 AC 了


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【大数】的更多相关文章

  1. HDU 1212 Big Number 大数模小数

    http://acm.hdu.edu.cn/showproblem.php?pid=1212 题目大意: 给你一个长度不超过1000的大数A,还有一个不超过100000的B,让你快速求A % B. 什 ...

  2. hdu 5898 odd-even number 数位DP

    传送门:hdu 5898 odd-even number 思路:数位DP,套着数位DP的模板搞一发就可以了不过要注意前导0的处理,dp[pos][pre][status][ze] pos:当前处理的位 ...

  3. hdu 2665 Kth number

    划分树 /* HDU 2665 Kth number 划分树 */ #include<stdio.h> #include<iostream> #include<strin ...

  4. 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/ ...

  5. 主席树[可持久化线段树](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 ...

  6. 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 ...

  7. HDU 1212 Big Number(C++ 大数取模)(java 大数类运用)

    Big Number 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1212 ——每天在线,欢迎留言谈论. 题目大意: 给你两个数 n1,n2.其中n1 ...

  8. 题解报告:hdu 1212 Big Number(大数取模+同余定理)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1212 Problem Description As we know, Big Number is al ...

  9. hdu 1212 Big Number(大数取模)

    Problem Description As we know, Big Number is always troublesome. But it's really important in our A ...

随机推荐

  1. Unity3D导入外部任务模型无法触发鼠标事件解决方案

    前几日 在做U3D测试的时候 导入了网上的一个人物模型 但是后来发现无论如何该模型都无法响应诸如:OnMouseDown 这些鼠标事件 又用U3D自带的水管工做了测试 发现不是我系统的问题= = 水管 ...

  2. jsp中URL传递中文參数的处理

    在页面的url中使用encodeURI(encodeURI(中文)).对中文进行编码.并在server的java程序中使用URLDecoder.decode(中文, "UTF-8" ...

  3. dev_queue_xmit()函数返回值问题

    函数  dev_queue_xmit()用于直接使用sk_buf发包,此函数有返回值,但是并不能通过 此函数返回值为0来说明包已经发送出去且可以立刻释放sk_buff内存.因为网卡发包是一个异步的过程 ...

  4. Vue-router(vue2.0)用法示例

    一.新建3个组件 1./src/components/post.vue <template> <div> hello world! this is POST! </div ...

  5. linux bash shell run ros launch file and multi_node

    #!/bin/bash #source /opt/ros/melodic/setup.bash #source /home/pi/catkin_ws/devel/setup.bash #ROS_PAC ...

  6. vi/vim复制粘贴命

    1. 选定文本块.使用v进入可视模式,移动光标键选定内容. 2.复制的命令是y,即yank(提起) ,常用的命令如下:     y      在使用v模式选定了某一块的时候,复制选定块到缓冲区用:   ...

  7. WAS集群系列(3):集群搭建:步骤1:准备文件

    说明:"指示轨迹"为"点选顺序",截图为点击后效果截图 环境 项目点 指标 WAS版本号 7.0 操作系统 Windows 2008 系统位数 64bit 内存 ...

  8. linux flush memcache缓存

    telnet localhost 11211 flush_all  memcached Telnet Interface Command Description Example get Reads a ...

  9. UIview层次管理

    将一个UIView显示在最前面只需要调用其父视图的 bringSubviewToFront()方法. 将一个UIView层推送到背后只需要调用其父视图的 sendSubviewToBack()方法.

  10. EJB是什么?(节选)

    近期的项目中使用了EJB.当时就仅仅知道怎么用,没有深入的去理解.当完毕这个项目之后.再回想项目中使用的技术.框架以及工具的时候,突然感觉对EJB这个概念非常是模糊,于是上网搜一些资料.可是,非常多的 ...