HDOJ 4608 I-number

来源:互联网 发布:明源软件上海分公司 编辑:程序博客网 时间:2024/05/17 05:57

题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=4608


I-number

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3105    Accepted Submission(s): 1165


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
1202
 

Sample Output
208
 

Source
2013 Multi-University Training Contest 1
 

题意: 给一个正整数x ,要你求最小的y。 使得的y>x 且y的各个位数之和能被10整除。 x的程度不超过 105.

题解: 简单大数加法 .

#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;}


0 0
原创粉丝点击