-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex1011.cpp
More file actions
37 lines (29 loc) · 751 Bytes
/
ex1011.cpp
File metadata and controls
37 lines (29 loc) · 751 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
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
inline
bool is_shorter(const std::string &a, const std::string &b)
{
return a.size() < b.size();
}
void print_vec(std::vector<std::string> &vec)
{
for (auto &elem: vec)
std::cout << elem << " ";
std::cout << std::endl;
}
void eliminate_duplicates(std::vector<std::string> &vec)
{
std::stable_sort(vec.begin(), vec.end(), is_shorter);
auto end_unique = std::unique(vec.begin(), vec.end());
vec.erase(end_unique, vec.end());
}
int main()
{
std::vector<std::string> s_vec = {"aa", "aaa", "bb", "bbb", "cc" ,"cc", "ccc", "ddddd"};
print_vec(s_vec);
eliminate_duplicates(s_vec);
print_vec(s_vec);
return EXIT_SUCCESS;
}