Official
B - Qualification Contest Editorial by cn449
上位 \(K\) 人の人のハンドルネームは \(S_1, S_2, \ldots, S_K\) です。
よって、配列 \((S_1, S_2, \ldots, S_K)\) を 辞書順に並べ替えればよいです。
この操作は sort 関数などの名前で多くの言語に標準で定義されている文字列からなる配列を辞書順に並べ替える関数を用いることにより実現できます。
実装例 (C++)
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
vector<string> a;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
if (i < k) a.push_back(s);
}
sort(a.begin(), a.end());
for (string s : a) cout << s << '\n';
}
posted:
last update: