看到去重+排序(数据范围不是很大)直接用桶排序
上AC代码:
#include<bits/stdc++.h>
using namespace std;
bool number[1000]; //1000个“桶”
int main()
{
int N, sum = 0, s;
cin>>N;
for(int i = 1; i<=N; ++i)
{
cin>>s;//读入数据
if(!number[s])//如果这个数没有出现过
{
number[s] = 1;//标记为出现
++sum;//计数器+1
}
}
cout<<sum<<endl;//输出不相同的数的个数
for(int i=0; i<1000; ++i)//遍历数组
if(number[i])//如果出现过就输出
cout<<i<<' ';
return 0;//结束程序
}