首页 > 代码库 > set vector 删除重复元素

set vector 删除重复元素

 1 #include <iostream>
 2 #include<cstdio>
 3 #include <vector>
 4 #include <set>
 5 #include <iterator>
 6 using namespace std;
 7 
 8 int main()
 9 {
10     set<int>s;
11     cout << "please input the number of vector‘s element " << endl;
12     int n;
13     cin >> n;
14     for (int i = 0; i < n; i++)
15     {
16         int temp;
17         cin >> temp;
18         s.insert(temp);
19     }
20     vector<int>v;
21     insert_iterator<vector<int> > in_it(v, v.begin());
22     copy(s.begin(), s.end(), in_it);
23     printf("%d\n",v.size());
24     for (vector<int>::iterator it = v.begin(); it != v.end(); it++)
25     {
26         cout << *it << " ";
27     }
28     return 0;
29 }

 

set vector 删除重复元素