題目:
https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=448&page=show_problem&problem=4458
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| #include <bits/stdc++.h> using namespace std;
int main(){ ios::sync_with_stdio(0); cin.tie(0); int arr[100005];
fill(arr, arr+100005, 0); for(int i=1; i<100005; ++i){ int x = i, y = i; while(x > 0){ y += x%10; x/=10; } if(arr[y] == 0 || i < arr[y]) arr[y] = i; }
int t, n; cin >> t; while(t--){ cin >> n; cout << arr[n] << '\n'; } return 0; }
|