-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10.11.cpp
More file actions
40 lines (35 loc) · 884 Bytes
/
10.11.cpp
File metadata and controls
40 lines (35 loc) · 884 Bytes
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
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
using std::stable_sort;
using std::sort;
using std::unique;
using std::vector;
using std::cin;
using std::cout;
using std::endl;
using std::string;
std::ostream &print(std::ostream &os, const vector<string> &vec) {
for (const string &s : vec)
cout << s << ' ';
return os;
}
bool isShorter(const string &s1, const string &s2) {
return s1.size() < s2.size();
}
void elimDups(vector<string> &vec) {
sort(vec.begin(), vec.end());
vector<string>::iterator endUnique = unique(vec.begin(), vec.end());
vec.erase(endUnique, vec.end());
}
int main() {
vector<string> words;
for (string temp; cin >> temp; words.push_back(temp)) ;
print(cout, words) << '\n';
elimDups(words);
print(cout, words) << '\n';
stable_sort(words.begin(), words.end(), isShorter);
print(cout, words) << endl;
return 0;
}