题目:



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. Java 中 ConcurrentHashMap 原理分析

    一.Java并发基础 当一个对象或变量可以被多个线程共享的时候,就有可能使得程序的逻辑出现问题. 在一个对象中有一个变量i=0,有两个线程A,B都想对i加1,这个时候便有问题显现出来,关键就是对i加1 ...

  2. ionic开发之优化目录结构

    当我们来个ionic start circleApp tabs的时候,会自动生成目录结构,基本如下: 显然这不利于项目的管理,当你的项目越来越复杂的时候,这是不够的.我们必须要按照模块进行文件夹的方式 ...

  3. URL相对路径和URL绝对路径

    经常在页面中引用图片,html页面等,自己常常弄错相对路径和绝对路径,今天写下此文总结一下.    直接举例说明吧. 在 D:\例子\html下有这么几个文件和文件夹     1.若引用的资源和本身在 ...

  4. react-native + teaset 实现 Tabbar

    1.代码 src/pages/MainPage/index.js /** * 主页面 */ import React, {Component} from 'react'; import { BackH ...

  5. Android Studio Gradle项目中加入JNI so文件

    首先在Android Studio(版本号1.2.2)project的app文件夹下创建整个jni文件夹,jni文件夹里写Android.mk.Application.mk以及各类C/C++和汇编源文 ...

  6. 【BIEE】分析的解析机制

    今天使用BIEE时意外的发现个问题,BIEE在展示结果时候,是先进行排序,然后再展示.具体测试案例如下: 首先,存在如下数据: 在BIEE展示效果如下: 目前是根据O1,02,03,04,05,06, ...

  7. rational rose画UML图

    原文见:http://blog.csdn.net/cjr15233661143/article/details/8532997 UML是一种建模语言,是系统建模的标准.我们之所以建模是因为大规模的系统 ...

  8. 【优才原创】Android的拖放机制

    优才网 [优才原创]Android的拖放机制 2016-04-18 优才学院 优才网 一.拖放机制概述 ² 拖放操作是手指触摸屏幕上的某一对象.然后拖动该对象.最后在屏幕的某个位置释放该对象并运行某种 ...

  9. Windows App开发之编辑文本与绘制图形

    编辑文本及键盘输入 相信大家都会使用TextBox,但假设要让文本在TextBox中换行该怎么做呢?将TextWrapping属性设置为Wrap,将AcceptsReturn属性设置为True就好咯. ...

  10. springboot学习(二) 第一个springboot项目:Hello World!

    1.简介 可以像使用其他java标准库那样使用spriongboot,只需简单地在你的classpath下包含正确的 spring-boot-*.jar 文件.springboot不需要集成任何特殊的 ...