1583 - Digit Generator

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/HackQ_sxj/article/details/88357379
#include <stdio.h>
#include <string.h>
#define maxn 100005
int a[maxn];

int main()
{
    int T, n;
    memset(a, 0, sizeof(a));
    for(int i = 1; i < maxn; i++)
    {
        int x = i, y = i;
        while(x > 0)
        {
            y += x%10;
            x /= 10;
        }
        if(a[y] == 0||i < a[y]) a[y] = i;
    }
    scanf("%d", &T);
    while(T--){
        scanf("%d", &n);
        printf("%d\n", a[n]);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/HackQ_sxj/article/details/88357379