4003. I-number

来源:互联网 发布:淘宝上的日系店铺 编辑:程序博客网 时间:2024/05/19 20:20

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

#include<iostream>#include<string>#include<stdio.h>#include<string.h>using namespace std;char s[100010],s1[100001];int f(char s[]){int l=strlen(s),sum=0;for(int i=0;i<l;i++)sum=sum+(s[i]-'0');return sum%10==0;}void add(char s[]){int l=strlen(s),i;i=l-1;s[i]++;while(s[i]>'9'){s[i]='0';s[i-1]=s[i-1]+1;i--;}}int main(){int t,x,l;cin>>t;while(t--){s[0]='0';scanf("%s",s+1);add(s);while(!f(s))add(s);if(s[0]=='0')printf("%s\n",s+1);elseprintf("%s\n",s);}return 0;}

0 0
原创粉丝点击