-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprog10.11.cpp
35 lines (33 loc) · 1.21 KB
/
prog10.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
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <functional>
template<typename T>
struct isShorter {
isShorter(){};
bool operator()(T a, T b) const{
return a.size() < b.size();
}
};
template<typename T, template <typename, typename> class Container, typename Comparator = std::less<T>>
void elimDups(Container<T, std::allocator<T>> &values,
void(*sorter)(typename Container<T, std::allocator<T>>::iterator, typename Container<T, std::allocator<T>>::iterator, Comparator) = std::sort,
Comparator comp = Comparator()){
sorter(values.begin(),values.end(),comp);
auto end_unique = std::unique(values.begin(), values.end());
values.erase(end_unique, values.end());
}
/*template<typename T, template <typename, typename> class Container>
bool isShorter(Container<T, std::allocator<T>> a, Container<T, std::allocator<T>> b){
return a.size() < b.size();
}*/
int main(){
// input
std::vector<std::string> svec;
for (std::string str; std::cin >> str; svec.emplace_back(str));
// process
elimDups(svec);
elimDups(svec, std::stable_sort, isShorter<std::string>());//std::greater<std::string>()
for (const auto& elem : svec) std::cout << elem << std::endl;
}