#include<set>
#include<iostream>
// no duplicated numbers
using namespace std;
struct myComp{
bool operator()(const int &a, const int &b)
{
if(a != b)
return a > b; // from large to small
else
return a > b;
}
};
int main()
{
set<int, myComp> s;
int n, x;
scanf("%d", &n);
for(int i = 0; i < n; i ++)
{
scanf("%d", &x);
s.insert(x);
}
set<int, myComp> :: iterator it;
for(it = s.begin(); it != s.end(); it ++)
cout<< *it << " ";
return 0;
}
STL容器——set实现自定义排序(无重复元素)
于 2022-02-05 17:58:04 首次发布