#include <bits/stdc++.h>
using namespace std;
const int N=1e5+10;
bool st[N];
int main()
{
std::ios::sync_with_stdio(false);std::cin.tie(nullptr);
int n;
cin>>n;
vector<int> a;
for(int i=0;i<n;++i)
{
int x;
cin>>x;
if(!st[x])
{
a.push_back(x);
st[x]=true;
}
}
sort(a.begin(),a.end());
for(auto x:a)
cout<<x<<" ";
return 0;
}
没有给出数据范围,盲猜每个数的大小不超过1e5。开一个bool数组,用桶的思想,每次输入时,判断该数有没有出现过,若是第一次出现加入待排序序列中,并记录已经出现。如果已经出现过,则不加入待排序序列。最后用内置函数sort排序。这边因为不清楚待排序序列的长度,所以采用vector,用数组也完全可以。

京公网安备 11010502036488号