Title Source: http://acm.hdu.edu.cn/showproblem.php?pid=4608
I-numberTime
limit:10000/5000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 3105 Accepted Submission (s): 1165
Problem DescriptionThe I-number of x is defined to being an integer y, which satisfied the the conditions below:
1.y>x;
2.The sum of each digit of Y (under base) is the multiple of 10;
3.Among all integers this satisfy the conditions above, y shouble be the minimum.
Given x, you ' re required to calculate the I-number of X.
Inputan integer T (t≤100) would exist in the first line of input, indicating the number of test cases.
The following T lines describe all the queries and each with a positive integer x. The length of x would not exceed 105.
Outputoutput the I-number of x for each query.
Sample Input
1202
Sample Output
208
Source2013 multi-university Training Contest 1
Test instructions: Give a positive integer x to ask you for the smallest Y. The sum of the y>x and the number of bits of y can be divisible by 10. The degree of x is not more than5.
A simple, large number of additions.
#include <iostream> #include <string> #define MAXN 100000+5 using namespace std;string str;int sum=0,t;int Calcbit (string &x) {int s=0;for (int i=0;i<x.size (); i++) s+= (x[i]-' 0 '); return s;} void Add (String &x) {string temp= ""; char ch;int num[maxn]={0},len=x.size (); for (int i=0;i<len;i++) num[i]= (x[ len-i-1]-' 0 '); num[0]++;for (int i=0;i<len;i++) {if (num[i]>9) {num[i+1]+=num[i]/10;num[i]%=10;}} int i;for (I=len;i>0&&!num[i];) i--;for (; i>=0;i--) temp+= (num[i]+ ' 0 '); len=temp.size (); for (int i=0;i <=len/2;i++) {ch=x[i];x[i]=x[len-i-1];x[len-i-1]=ch;} X=temp;} int main () {Cin.sync_with_stdio (false); Cin>>t;while (t--) {cin>>str; Add (str); sum=calcbit (str); while (sum%10) {Add (str); sum=calcbit (str);} Cout<<str<<endl;} return 0;}
Hdoj 4608 I-number