I-number
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1610 Accepted Submission(s): 661
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.
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.
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
题意:
定义一个数 y 为 x 的 I-number。对于 y 有如下要求:
1、y > x;
2、y 的每一位之和要为10的倍数(例如 28 每一位之和为 10 ,为 10 的 1 倍);
3、这样的 y 有很多个,但是I-number为最小的那个
注意: 有恶心的前导 0 , 而且不能删除这些前导 0 。 例如,202 对应的 I-number为208。 但如果他输入的是 000202 , 那么输出是 000208 这样。
符合要求的 y 一定满足 y < x + 20代码思路: 设计比较好的模块化编程思想,对于写这中大数模拟题比较好。其实很多解题代码写的很好,但是看不下去。同学们可以改改编程风格,大数写法还是2个
指针的应用。另外值得注意的是使用string +链接是很慢的。
#include <iostream> #include <string.h> #include <string> #include <algorithm> #include <stdio.h> #include <queue> #include <set> #include <limits.h> #define Max(a,b) ((a)>(b)?(a):(b)) using namespace std ; typedef long long LL ; const int size=100008 ; struct BigNum{ string str ; BigNum(){} BigNum(string s):str(s){} BigNum add(BigNum A){ int i , j ,jin=0 ,k=0; i=str.length()-1 ; j=A.str.length()-1 ; char sum[size] ,ans[size]; char c[2] ; while(i>=0&&j>=0){ sum[k++]=(str[i]-'0'+A.str[j]-'0'+jin)%10 +'0'; jin=(str[i]-'0'+A.str[j]-'0'+jin)/10 ; i-- ; j-- ; } while(i>=0){ sum[k++]=(str[i]-'0'+jin)%10 +'0'; jin=(str[i]-'0'+jin)/10 ; i-- ; } if(jin!=0) sum[k++]='1' ; j=0 ; for(i=k-1;i>=0;i--) ans[j++]=sum[i] ; ans[j]='