[2006年NOIP普及组] 明明的随机数

试题解析:本题要运用排序,题目要求去重+排序,而且每个数最大不超过1000,数据较小,所以我们就可以直接使用桶排。然后要先输出个数,再输出每个数

#include<bits/stdc++.h>
using namespace std;
int s;
struct a {
int sz;
} b[2000];
int main() {
int n,i,j;
cin>>n;
for(i=1; i<=n; i++) {
cin>>j;
b[j].sz=1;
}
for(i=1; i<=1000; i++) {
s=s+b[i].sz;
}
cout<<s<<endl;
for(i=1; i<=1000; i++) {
if(b[i].sz>0) {
cout<<i<<" ";
}
}
}

posted @ 2022-08-13 08:35  TheMagician  阅读(42)  评论(0)    收藏  举报