题目:



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. 最长公共字串算法, 文本比较算法, longest common subsequence(LCS) algorithm

    ''' merge two configure files, basic file is aFile insert the added content of bFile compare to aFil ...

  2. SQLiteDatabase中query、insert、update、delete方法参数说明

    1.SQLiteDataBase对象的query()接口: public Cursor query (String table, String[] columns, String selection, ...

  3. Linux(Centos)——下升级python3.3

    CentOS下的Python版本一般都比较低,很多应用都需要升级python来完成.我装的centOS的默认的python版本是V2.4.3,但运行node.js需要的版本是2.5以上. 1.下载py ...

  4. MySQL几个性能指标

    近期参加了一个DBA MySQL的分享,主要从MySQL的性能指标分析.同步及运维三个方面分享一些经验,其中,一些经验值还是值得记录下来的: 对于一个MySQL实例,CRUD上限经验值如下: Quer ...

  5. Sencha Test Futures API 探秘

    原文链接:http://blog.csdn.net/lovelyelfpop/article/details/52301249 英文原文:<Inside the Sencha Test Futu ...

  6. 【我们都爱Paul Hegarty】斯坦福IOS8公开课个人笔记30 ScrollView Demo实战

    在上一话中我们创建了一个通过URL读取图片的Demo,这个Demo是不能拖动和缩放的.如今给它添加选项让它能够手动切换URL,并把图片加入到ScrollView中. 向Storyboard中拖入一个s ...

  7. IP数据库生成器

    代码地址如下:http://www.demodashi.com/demo/12688.html 项目放在github上,python版本ipdb_creator,java版本ip-locator. 项 ...

  8. 基于RxJava2+Retrofit2精心打造的Android基础框架

    代码地址如下:http://www.demodashi.com/demo/12132.html XSnow 基于RxJava2+Retrofit2精心打造的Android基础框架,包含网络.上传.下载 ...

  9. NSNotification的几点说明

    1.NSNotification消息的同步性 ①NSNotification使用的是同步操作.即如果你在程序中的A位置post了一个NSNotification,在B位置注册了一个observer,通 ...

  10. 监听EditText字数

    editContent.addTextChangedListener(new TextWatcher() { private CharSequence temp;private int editSta ...