The title is no longer written, vj:https://vjudge.net/problem/uva-1583#author=0.
The main thing is to find a number less than it's a number, less than its number each add up plus that number will be equal to the original number. No, it's 0.
The problem actually feels like a direct violence for the right. The largest number is 1e5. So up to 5 9 so that's 45, just use StringStream or other methods to split the position and look for the line.
Find the break then this number is the smallest.
Rujia's practice is to directly preprocess an array and then find the number based on the array, it is very smart, and the code is also relatively small.
Code:
#include <iostream>using namespacestd;#defineMax 100010intA[max];main () { for(intI=1; i<max;i++) { intX=i;inty=i; while(x) {y+=x%Ten; x/=Ten;} if(a[y]==0|| I<a[y]) a[y]=i; } intp,b; CIN>>p; while(p--) {cin>>b; cout<<a[b]<<Endl; }}
This kind of thought should pay attention to!!! Direct preprocessing.
UVA 1583 Digit Generator (Uva-1583)