可以用到这几个函数
sort(vec.begin(), vec.end());
auto end_unique = unique(vec.begin(), vec.end());
vec.erase(end_unique, vec.end());
具体代码如下:
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int ssss()
{
vector<int> vec;
int n, num;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> num;
vec.push_back(num);
}
sort(vec.begin(), vec.end());
auto end_unique = unique(vec.begin(), vec.end());
vec.erase(end_unique, vec.end());
for (auto it = vec.begin(); it != vec.end(); it++)
cout << *it << endl;
system("pause");
return 0;
}
网友评论