CSP历年复赛题-P1059 [NOIP2006 普及组] 明明的随机数

原题链接:https://www.luogu.com.cn/problem/P1059

题意解读:此题主要做两件事:排序+去重,用计数排序即可解决,直接给出代码。

100分代码:

#include <bits/stdc++.h>
using namespace std;

const int N = 1005;

int a[N];
int n;

int main()
{
    cin >> n;
    int x;
    int cnt = 0;
    for(int i = 1; i <= n; i++)
    {
        cin >> x;
        if(!a[x])
        {
            cnt++;
        }
        a[x]++;
    }
    cout << cnt << endl;
    for(int i = 1; i <= 1000; i++)
    {
        if(a[i]) cout << i << " ";
    }
    return 0;
}

 

posted @   五月江城  阅读(21)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
· 【杂谈】分布式事务——高大上的无用知识?
点击右上角即可分享
微信分享提示