-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path11.cpp
43 lines (37 loc) · 959 Bytes
/
11.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
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
void print(vector<string> v) {
for(auto i : v) {
cout << i << " ";
}
cout << endl;
cout << "------------" << endl;
}
bool isShorter(const string &s1, const string &s2){
return s1.size() < s2.size();
}
// eliminating duplicates
void elimDups(vector<string> &words){
print(words);
sort(words.begin(), words.end());
print(words);
auto end_unique = unique(words.begin(), words.end());
print(words);
words.erase(end_unique, words.end());
print(words);
}
int main(){
vector<string> words = {"the", "quick", "red", "fox", "jumps", "over", "the", "slow", "aed", "turtle"};
sort(words.begin(), words.end(), isShorter);
cout << "------" << endl;
print(words);
elimDups(words);
std::vector<string> words2(words);
sort(words.begin(), words.end(), isShorter);
print(words);
stable_sort(words2.begin(), words2.end(), isShorter);
print(words2);
}