[蓝桥杯][算法训练VIP]寂寞的数 Easy only once

基本思想:

感觉也不用贪心思想,直接打表就可以了;

关键点:

无;

#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<vector> 
#include<string>
#include<math.h>
#include<algorithm>
#include<cstring>
#include<map>
#include<queue>
#include<set>
#include<stack>
using namespace std;

const int maxn = 20000;

int change(int x) {
    int cnt = x;
    while (x != 0) {
        cnt += x % 10;
        x = x / 10;
    }
    return cnt;
}

vector<int>num(maxn);
int main() {
    int m;
    cin >> m;
    int n;
    for (int i = 1; i <= m; i++) {
        n = change(i);
        num[n]++;
        //cout << i << endl;
    }
    for (int i = 1; i <= m; i++) {
        if (num[i]==0)
            cout << i << endl;
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/songlinxuan/p/12353704.html