forked from jaege/Cpp-Primer-5th-Exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
/
10.9.cpp
28 lines (24 loc) · 776 Bytes
/
10.9.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
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
std::ostream &print(std::ostream &os, const std::vector<std::string> &vs) {
for (const auto &i : vs)
os << i << " ";
return os;
}
void elimDups(std::vector<std::string> &words) {
print(std::cout, words) << words.size() << std::endl;
std::sort(words.begin(), words.end());
print(std::cout, words) << words.size() << std::endl;
auto end_unique = std::unique(words.begin(), words.end());
print(std::cout, words) << words.size() << std::endl;
words.erase(end_unique, words.end());
print(std::cout, words) << words.size() << std::endl;
}
int main() {
std::vector<std::string> words;
for (std::string s; std::cin >> s; words.push_back(s)) {}
elimDups(words);
return 0;
}