Digit Generator 打表

刘汝佳的新题,打表就过了

#include<cstdio>
#include<cstring>
using namespace std;
#define MAXD 100000 + 10
int vis[MAXD];
void biao(){
    memset(vis,0,sizeof(vis));
    for(int i = 1 ; i <= MAXD - 10 ; i++){
        int ans = i;
        int sum = ans;
        while(ans){
            sum = sum + (ans % 10);
            ans /= 10;
        }
        if(sum <= MAXD - 10 && vis[sum] == 0)
            vis[sum] = i;
    }
}
int main(){
    biao();
    int T;
    scanf("%d",&T);
    while(T--){
        int n;
        scanf("%d",&n);
        printf("%d\n",vis[n]);
    }
    return 0;
}


你可能感兴趣的:(Digit Generator 打表)