-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathPage386_predicate.cpp
More file actions
32 lines (32 loc) · 879 Bytes
/
Page386_predicate.cpp
File metadata and controls
32 lines (32 loc) · 879 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
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using std::cout;
using std::endl;
using std::string;
using std::vector;
bool isShorter(const string &s1, const string &s2)
{
return s1.size() < s2.size();
}
void elimDups(vector<string> &words)
{
sort(words.begin(), words.end());
auto end_unique = unique(words.begin(), words.end());
words.erase(end_unique, words.end());
}
int main()
{
vector<string> story = { "the", "quick", "red", "fox", "jump", "over", "the", "slow", "red", "turtle" };
elimDups(story);
for(const auto &s : story)
cout << s << " ";
cout << endl;
// we cannot put isShorter into sort, or the first order will be length rather than alphabet
stable_sort(story.begin(), story.end(), isShorter);
for(const auto &s : story)
cout << s << " ";
cout << endl;
return 0;
}