題意:給出一個正整數x,求最小的整數y,知足y > x且y的全部位的數字和是10的倍數。(x <= 100000)php
題目連接:http://acm.hdu.edu.cn/showproblem.php?pid=4608spa
——>>每次自身+1,知足條件即跳出。坑點:輸入025,應輸出028,輸入01,應輸出19。code
#include<cstdio> #include<cstring> using namespace std; const int maxn = 100000 + 10; char a[maxn]; int b[maxn]; int main(){ int T,i,j; scanf("%d", &T); while(T--){ scanf("%s", a); int len = strlen(a); memset(b, 0, sizeof(b)); for(i = len-1; i >= 0; i--) b[len-1-i] = a[i]-'0'; bool flag = 1; while(flag){ b[0]++; for(i = 0; i < len; i++){ if(b[i] >= 10){ b[i+1]++; b[i] %= 10; } } if(b[len] > 0) len++; int sum = 0; for(i = 0; i < len; i++) sum += b[i]; if(sum % 10 == 0){ for(j = len-1; j >= 0; j--) printf("%d", b[j]); printf("\n"); flag=0; } } } return 0; }