I-number

Time Limit: 5000ms   Memory limit: 65536K  有疑问?点这里^_^

题目描写叙述

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.

输入

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 the I-number of x for each query.

演示样例输入

1
202

演示样例输出

208

提示

来源

2013 Multi-University Training Contest 1
 
我不得不说这道题真的非常坑,我要是不搜题解预计是毁掉了 本来题意非常easy,就是给定一个x(因为可能非常大用字符串模拟),求出比x大的且各位数字之和为10的倍数的数,
要求输出符合上诉条件的最小数。

but,这个x居然是能够有前导0的(它没说)也就是说输入 00202 输出 00208

 
代码略挫QAQ
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <cstdio>
#include <cctype>
using namespace std;
char x[100010];
int digitsum()
{
int sum=0;
for(int i=0;i<strlen(x);i++)
sum+=(x[i]-'0');
return sum;
}
int is_o()
{
for(int i=0;i<strlen(x);i++)
if(x[i]!='0') return 0;
return 1;
}
int main()
{
int i,T;
cin>>T;
getchar();
while(T--)
{
cin>>x;
int s=-99;
while(s%10)
{
int p=strlen(x)-1;
int len=strlen(x);
x[p]++;
while(x[p]>'9')
{
x[p--]-=10;
if(p>=0)
x[p]++;
}
if(is_o())
{
x[0]='1';
for(i=1;i<=len;i++)
x[i]='0';
x[i]='\0';
}
s=digitsum();
}
cout<<x<<endl;
}
return 0;
}

 

HDU 4608 I-number(模拟)的更多相关文章

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

  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 3711 Binary Number(暴力 模拟)

    Problem Description For non-negative integers x and y, f(x, y) , )=,f(, )=, f(, )=. Now given sets o ...

  7. HDU 5510---Bazinga(指针模拟)

    题目链接 http://acm.hdu.edu.cn/search.php?action=listproblem Problem Description Ladies and gentlemen, p ...

  8. hdu 2665 Kth number(划分树模板)

    http://acm.hdu.edu.cn/showproblem.php?pid=2665 [ poj 2104 2761 ]  改变一下输入就可以过 http://poj.org/problem? ...

  9. HDU 5935 Car 【模拟】 (2016年中国大学生程序设计竞赛(杭州))

    Car Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...

随机推荐

  1. Maven、gradle、Ant、Eclipse IDE

    Maven.gradle.Ant.Eclipse IDE之间的关系 http://wenku.baidu.com/view/d33208810912a21615792910.html?from=sea ...

  2. bzoj1061 1283

    以前写的1061但一直没懂,后来懂了但忘写解题报告了 做了1283顺便补一下吧 1061 我是orz https://www.byvoid.com/blog/noi-2008-employee/#mo ...

  3. SQL、LINQ、Lambda 三种用法

    SQL   LinqToSql   Lambda 1. 查询Student表中的所有记录的Sname.Ssex和Class列.select sname,ssex,class from studentL ...

  4. ssh-keygen+ssh-copy-id 在linux下实现ssh无密码登录访问

    环境: 192.168.2.10 192.168.2.11 实现:2.10 ssh无需密码登录到2.11 在2.10 ssh到2.11机器上,需要密码,这样对一些脚本工作不方便,因为需要密码,也就是需 ...

  5. POJ 1001 Exponentiation

    题意:求c的n次幂……要求保留所有小数…… 解法:一开始只知道有BigInteger……java大数+模拟.第一次写java大数……各种报错各种exception……ORZ 没有前导0和小数后面的补位 ...

  6. java jvm学习笔记六(实现写自己的安全管理器)

    安全管理器SecurityManager里设计的内容实在是非常的庞大,它的核心方法就是checkPerssiom这个方法里又调用AccessController的checkPerssiom方法,访问控 ...

  7. java基础之数据类型转换

    在写java程序时,经常会遇到需要数据类型转换,下面我们来介绍一些一些基本数据类型之间的转换. 1.int,folat,double,boolean,long 转换成字符串,其实很简单只需使用一个函数 ...

  8. <转>SpringMVC与Struts2 比较总结

    原链接:http://blog.csdn.net/chenleixing/article/details/44570681 个人整理: 1.级别不同:SpringMVC :方法  Struts是 类级 ...

  9. 最短路径算法Dijkstra和A*

    在设计基于地图的游戏,特别是isometric斜45度视角游戏时,几乎必须要用到最短路径算法.Dijkstra算法是寻找当前最优路径(距离原点最近),如果遇到更短的路径,则修改路径(边松弛). Ast ...

  10. class0513(html基础加强)

    内容:HTML.CSS 目标:掌握手写HTML实现一般难度的Web页面的能力(如网站注册表单),为ASP.Net学习打基础.坚持手写HTML,可视化设计只是一种自学的手段. 参考书:张孝祥<Ja ...