-
Notifications
You must be signed in to change notification settings - Fork 1
/
p334 检测unique.cpp
56 lines (47 loc) · 1.13 KB
/
p334 检测unique.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//p334 检测unique
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;
//将vec打印输出
void output(vector<string> &vec)
{
for (vector<string>::iterator iter = vec.begin(); iter != vec.end(); ++iter)
cout << *iter << "\t";
cout << endl;
}
int main()
{
vector<string> words;
words.push_back("a");
// words.push_back("a");
// words.push_back("b");
words.push_back("b");
words.push_back("b");
// words.push_back("c");
words.push_back("c");
words.push_back("d");
// words.push_back("slow");
// words.push_back("the");
// words.push_back("the");
// words.push_back("turtle");
//out
output(words);
//排序
sort(words.begin(), words.end());
output(words);
vector<string>::iterator end_unique = unique(words.begin(), words.end());
//out
output(words);
words.erase(end_unique, words.end());
//out
output(words);
return 0;
}
/*
fox jumps over quick red red slow the the turtle
fox jumps over quick red slow the turtle the turtle
fox jumps over quick red slow the turtle
请按任意键继续. . .
*/