HDU 4608 I-number (数学&字符串处理)
I-number
http://acm.hdu.edu.cn/showproblem.php?pid=4608
Time Limit: 10000/5000 MS (Java/Others)
Memory Limit: 32768/32768 K (Java/Others)
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
题意:求一个大于x的且最接近x的数y,y所有数位上的数字和sum是10的倍数。
思路:由于x的长度可达10^5,采用字符串处理即可。
关键是判断能不能在不进位(只改变最后一个数)的时候找到y,此时把最后一位加上10 - sum%10就行。(需满足条件:最后一位 若最后一位进位,就先判断仅为之后所有位之和,比如57999进位后变58000,sum%10=3,那么最后一位加上10 - sum%10就行 特判:所有位数为9,那直接先输出一个1,然后把x最后一位变成9,剩下变成0就行。 完整代码: /*171ms,332KB*/
#include
本文仅代表作者观点,版权归原创者所有,如需转载请在文中注明来源及作者名字。
免责声明:本文系转载编辑文章,仅作分享之用。如分享内容、图片侵犯到您的版权或非授权发布,请及时与我们联系进行审核处理或删除,您可以发送材料至邮箱:service@tojoy.com



