枚举,暴力

可以先排序再去重或先去重再排序

建议直接上桶排序

以随机数作为索引,对应位置的元素置1,然后遍历一遍元素为1的索引即可

至于不同的随机数个数可以直接遍历一遍数组求和,得出的值即为不同的随机数的个数。

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

#define N 1010

int main(){
    int a[N],n,cnt = 0;
    
    for(int i = 0;i <= N;i++)    //初始化
        a[i] = 0;
    
    cin>>n;
    for(int i = 1;i <= n;i++){
        int temp;
        cin>>temp;
        a[temp] = 1;    //对应数标志位置1
    }
    
    for(int k = 1;k <= N;k++)    //所有标志位求和即为不同的随机数个数
        cnt += a[k];
    cout<<cnt<<endl;
    
    for(int j = 1;j <= N;j++)    //遍历数组中元素为1的索引
        if(a[j]) cout<<j<<' ';
    
    return 0;
}