-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathN20920.cpp
More file actions
48 lines (40 loc) · 887 Bytes
/
Copy pathN20920.cpp
File metadata and controls
48 lines (40 loc) · 887 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
38
39
40
41
42
43
44
45
46
47
48
#include <iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#define FASTIO cin.tie(nullptr); ios::sync_with_stdio(false);
using namespace std;
int N, M;
string str;
vector <string> voca;
map<string, int>m;
bool compare(string a, string b) {
if (a.size() == b.size() && m[a] == m[b]) {
return a < b;
}
else if (m[a] == m[b]) {
return a.size() > b.size();
}
return m[a] > m[b];
}
int main() {
FASTIO;
cin >> N >> M;
while (N--) {
cin >> str;
if (str.size() < M) {
continue;
}
if (str.length() >= M && m.find(str)==m.end()) {
m[str] = 0;
voca.push_back(str);
}
m[str]++;
}
sort(voca.begin(), voca.end(), compare);
for (int i = 0; i < voca.size(); i++) {
cout << voca[i] << '\n';
}
return 0;
}