I-number

 

I-number

Time Limit: 5000MS Memory limit: 65536K

题目描述

 
 题目描述
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.
输入
 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 the I-number of x for each query.
示例输入
1
202
示例输出
208
提示
题目意思:
输入x,输出y;
1.y>x;
2.y各位和是10的整倍数
3注意x,这是一个大数问题
 1 #include<cstdio>

 2 #include<cstring>

 3 int s[100005];

 4 int a(int n)//把数字+1,同时返回+1后的数字的各位数字和

 5 {

 6     int i,sum;

 7     s[n-1]++;

 8     i=n-1;

 9     while(s[i]>9&&i>0)//判断>9就连续进位,最后一位不进位

10     {

11         s[i]-=10;

12         s[--i]+=1;

13     }

14     sum=0;

15     i=n-1;

16     while(i>0)

17         sum+=s[i--];

18     if(s[0]<10)//最前面一位注意<10,就直接加进去

19         sum+=s[0];

20     else//否则就模拟进位

21     {

22         int a=s[0];

23         while(a)

24         {

25             sum+=a%10;

26             a/=10;

27         }

28     }

29     return sum;

30 }

31 int main()

32 {

33     char p[100005];

34     int n,len,i,sum;

35     scanf("%d",&n);

36     while(n--)

37     {

38         scanf("%s",p);

39         len=strlen(p);

40         for(i=0; i<len; i++)

41             s[i]=(p[i]-'0');//字符转数字

42         sum=a(len);//数字+1;

43         while(sum%10!=0)

44             sum=a(len);//持续+1;

45         for(i=0; i<len; i++)

46             printf("%d",s[i]);

47         printf("\n");

48     }

49     return 0;

50 }
View Code

 

 

 

 

你可能感兴趣的:(number)