I-number
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3969 Accepted Submission(s): 1416
Total Submission(s): 3969 Accepted Submission(s): 1416
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 10 5.
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 题意: 给出x,找到一个数满足下列条件 1.大于x 2.每个位置上的数字和是10的倍数 3.最小 x长度小于10^5 分析: 设sum表示x每个位置上数字的合值 对于x来说首先计算sum,如果x的个位加上10-sum小于等于9(即不进位),那么此时一定是要找的y 考虑进位情况,如果需要进位,那么直接把x的个位补足到0使它大于原来的x,此时x的个位为0,再次找sum,加上10-sum一定是y#include<cstring> #include<string> #include<iostream> #include<queue> #include<cstdio> #include<algorithm> #include<map> #include<cstdlib> #include<cmath> #include<vector> //#pragma comment(linker, "/STACK:1024000000,1024000000"); using namespace std; #define INF 0x3f3f3f3f char x[200005]; int getsum(int len) { int sum=0; for(int i=0;i<len;i++) { sum+=(x[i]-'0'); } return sum; } int getdis(int k) { int sum=0; while(k%10) k++,sum++; if(sum==0) sum=10; return sum; } void add(int d,int &len) { int index=0; while(index<len&&d) { int temp=(x[index]-'0'); x[index]=((temp+d)%10)+'0'; d=(temp+d)/10; index++; } if(d) x[len++]=d+'0'; } int main() { int T; scanf("%d",&T); while(T--) { scanf("%s",x); int len=strlen(x); for(int i=0;i<len/2;i++) { swap(x[i],x[len-i-1]); } int sum=getsum(len); int d=getdis(sum); if((x[0]-'0')+d<=9) add(d,len); else { add(10-(x[0]-'0'),len); int d=getsum(len); if(d%10!=0) add(getdis(d),len); } for(int i=len-1;i>=0;i--) { printf("%c",x[i]); } puts(""); } return 0; }