l3-5

https://vjudge.net/problem/UVA-1583

输入一个数n寻找 一个数使其各位相加等于n的最小数,打表;

#include <iostream>
#include<cstdio>
using namespace std;
const int N = 1e5+10;
int ans[N];
void makeform(){
    for(int i=1;i<N;i++){
        int number=i,ans1=i;
        while(number){
            ans1+=number%10;
            number/=10;
        }
        if(!ans[ans1])
        ans[ans1]=i;
    }
}
int main()
{
    int _;
    scanf("%d",&_);
    makeform();
    while(_--){
        int n;
        scanf("%d",&n);
        printf("%d\n",ans[n]);
    }
    //cout << "Hello world!" << endl;
    return 0;
}
发布了97 篇原创文章 · 获赞 3 · 访问量 9431

猜你喜欢

转载自blog.csdn.net/foolishpichao/article/details/100101237