-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path20920.cpp
More file actions
45 lines (39 loc) · 1.05 KB
/
20920.cpp
File metadata and controls
45 lines (39 loc) · 1.05 KB
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
44
45
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
bool compare(const pair<string, int>& a, const pair<string, int>& b) {
if (a.second != b.second) {
return a.second > b.second;
}
else if (a.first.size() != b.first.size()) {
return a.first.size() > b.first.size();
}
return a.first < b.first;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int word_count;
int min_len;
map<string, int> word_list;
string now_word;
cin >> word_count;
cin >> min_len;
for(int i = 0; i < word_count; i++) {
cin >> now_word;
if (now_word.size() < min_len)
continue;
auto it = word_list.find(now_word);
if (it == word_list.end())
word_list.insert(pair<string, int>(now_word, 1));
else
it->second++;
}
vector<pair<string, int> > vec(word_list.begin(), word_list.end());
sort(vec.begin(), vec.end(), compare);
for(auto word : vec) {
cout << word.first << "\n";
}
return 0;
}