首页 > 编程语言 > 详细

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

时间:2020-02-23 20:02:16      阅读:53      评论:0      收藏:0      [点我收藏+]

基本思想:

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

 

关键点:

无;

 

#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;
}

 

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

原文:https://www.cnblogs.com/songlinxuan/p/12353704.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!