数组排序、去重复

可以用到这几个函数

sort(vec.begin(), vec.end());

auto end_unique = unique(vec.begin(), vec.end());

vec.erase(end_unique, vec.end());

具体代码如下:

#include

#include

#include

using namespace std;

int ssss()

{

vector 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;

}

你可能感兴趣的:(数组排序、去重复)