题目链接https://vjudge.net/problem/UVA-1583
参考代码:
#include <iostream>
#include <stdio.h>
#include <string.h>
#define MaxSize 100005
int temp[MaxSize];
int main()
{
int T,n;
memset(temp,0,sizeof(temp));
for(int m = 1;m < MaxSize;m++)
{
int x = m,y = m;
while(x > 0)
{
y+=x%10;x/=10;
}
if(temp[y] == 0 || m < temp[y]) temp[y] = m;
}
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
printf("%d\n",temp[n]);
}
return 0;
}