I-number
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 0 Accepted Submission(s): 0
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 10 5.
Output
Output the I-number of x for each query.
Sample Input
1 202
Sample Output
208
Source
2013 Multi-University Training Contest 1
貌似是最水的一道。高精度每次加1就过去了。。。题目意思就是找个比x大且能各个数位上的和能被10整除的数。。
/*
* @author ipqhjjybj
* @date 20130723
*
*/
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <vector>
#include <string>
using namespace std;
#define inf 0x3f3f3f3f
#define MAXN 100005
#define clr(x,k) memset((x),(k),sizeof(x))
#define cpy(x,k) memcpy((x),(k),sizeof(x))
#define Base 10000
typedef vector<int> vi;
#define foreach(it,c) for(vi::iterator it = (c).begin();it != (c).end();++it)
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
char s[MAXN];
int num[MAXN];
int len;
void add(int a[],int num){
a[0]+=num;
for(int i=0;i<len;i++){
if(a[i]>9){
a[i+1]+=a[i]/10;
a[i]%=10;
}
}
while(a[len]){
a[len+1]=a[len]/10;
a[len]%=10;
len++;
}
// for(int i=len-1;i>=0;i--)
// printf("%d",a[i]);printf("\n");
}
int count(int a[]){
int sum=0;
for(int i = 0;i < len;i++)
sum+=a[i];
if(!(sum%10))
return 1;
else return 0;
}
int main(){
int t;
scanf("%d",&t);
while(t--){
scanf("%s",s);
len = strlen(s);
clr(num,0);
for(int i = len-1,j=0;i>=0;i--,j++)
num[i] = s[j]-'0';
do{
add(num,1);
}while(!count(num));
//print
for(int i=len-1;i>=0;i--)
printf("%d",num[i]);printf("\n");
}
return 0;
}