#include <bits/stdc++.h>
using namespace std;
struct node {
string s;
int of;
int id;
} a[100010];
int len = 0;
bool cmp(node x, node y) {
if (x.of != y.of) {
return x.of > y.of;
} else {
return x.id < y.id;
}
}
int main() {
int n, k;
cin >> n >> k;
cin.ignore();
for (int i = 0; i < 3 * n; i++) {
string tmp;
getline(cin, tmp);
if (len == 0) {
a[0].s = tmp;
a[0].of = 1;
a[0].id = 1;
len++;
} else {
int j = 0;
for ( ; j < len; j++) {
if (a[j].s == tmp) {
a[j].of++;
break;
}
}
if (j == len) {
a[len].s = tmp;
a[len].of = 1;
a[len].id = i+1;
len++;
}
}
}
sort(a, a + len, cmp);
for (int i = 0; i < k; i++) {
cout << a[i].s << endl;
}
return 0;
}
给定两个数字 N、K,以及 3×N 个字符串,求出出现次数最多(同样多时按照最先出现的编号降序排序)的 K 个字符串。