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. CodeWars题目筛选

    http://www.codewars.com/kata/search/csharp?q=&r%5B%5D=-8&xids=completed&beta=false 语言选择C ...

  2. SharePoint2013切换帐户登录菜单

    SharePoint2013帐户姓名显示的地方没有切换帐户的菜单,这个功能对于终端用户是可有可无的,但对于sharepoint管理员或sharepoint开发人员来讲,却是一个很重要的菜单,由于经常要 ...

  3. windows编译 obs-studio

    github下载源码 https://github.com/jp9000/obs-studio 还需要一个开发包 http://code.fosshub.com/OBS/download/depend ...

  4. centos nginx 多端口配置过程记录

    1. 编辑 /usr/local/nginx/vhosts/  在此目录下增加一文件,如;ci.ainux.com,或复制一个文件 修改其中的端口和目录,更改log_format 名称 重启nginx ...

  5. 在cshtml页面中,以‘@’开始的表达式 表示C#语句,会被编译执行

    在原始的Index.html中是正常显示的,然而在现在这个源代码是个cshtml页面: 但是在cshtml页面中,以‘@’开始的表达式 表示C#语句,会被编译执行,会去寻找controller传度给@ ...

  6. [转] MATLAB快捷键

    原文地址:MATLAB快捷键大全 (转载)作者:掷地有声 一.索引混排版 备注:删除了如F1(帮助)等类型的常见快捷命令 SHIFT+DELETE永久删除 DELETE删除 ALT+ENTER属性 A ...

  7. tap/click on search button on softkeyboard

    driver.sendKeyEvent(84);Appium says it successfully sent in the command but 'search' does not get ta ...

  8. Mac,WIN下支撑 IPV6的 sftp客户端

    transmit 这样的话就可以使用 ipv6了,教育网的优势体现出来了,window下得 支撑 ipv6的sftp客户端 Bitvise SSH 和 WINSCP

  9. 第一个App“今日材料报价”上架,记录一下【原】

    App Store地址:https://itunes.apple.com/us/app/jin-ri-cai-liao-bao-jia/id967274552?l=zh&ls=1&mt ...

  10. 【转载】chmod u+s

    转自:http://blog.chinaunix.net/uid-26642180-id-3378119.html Set uid, gid,sticky bit的三个权限的详细说明 一个文件都有一个 ...