#贴一道被自己蠢哭的题
#问题
I-number
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4500 Accepted Submission(s): 1588
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.
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.
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
#大数问题,我是第一次做,然后想到了当成字符串处理,然后手动做加法即可。但是由于长期对于超时的恐惧,我习惯性思维进行了手动加法,也就是自己完成位(数字那个)为单位的运算,而且我还头铁,不去每次重新计数和sum,而是自己去计算sum在进位时怎么改变的-_-一场考试在这道题上头铁了一个多小时。
#完成时枚举即可,不会超时,毕竟不会超过十次,每次检查一下sum%10,满足输出即可。
#!!!不要去掉前导0
#下面的代码不是我写的,是某位同志的博客里看见的,但是找不到是哪位同志的了。。。虽然不是原创,我还是把代码贴出来吧。
#代码我就读了一遍,所以没有加批注,只要逻辑的方向正确应该能直接理解,不要头铁。
#AC码
#include<stdio.h>
#include<string.h>
char num[100005];
int main()
{
int t;
int sum;
int i,j;
scanf("%d",&t);
while(t--)
{
sum=1;
num[0]='0';
num[1]='0';
scanf("%s",num+2);
int len=strlen(num);
for(i=0;i<len;i++)
num[i]=num[i]-'0';
while(sum%10)
{
sum=0;
j=len-1;
num[j]++;
while(num[j]>=10)
{
num[j-1]+=num[j]/10;
num[j]%=10;
sum+=num[j];
j--;
}
for(;j>=0;j--)
sum+=num[j];
}
i=1;
if(num[i]==0)//未进位
i++;
for(;i<len;i++)
printf("%d",num[i]);
printf("\n");
}
return 0;
}