#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
map <char, queue <string>> mp;
vector <string> names(n);
for (int i = 0; i < n; i++) {
cin >> names[i];
}
sort(names.begin(), names.end());
for (int i = 0; i < n; i++)
mp[names[i][0]].push(names[i]);
for (int i = 0; i < m; i++) {
char s;
cin >> s;
cout << mp[s].front() << '\n';
string tp = mp[s].front();
mp[s].pop();
mp[s].push(tp);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
52 ms |
12796 KB |
Output is correct |
8 |
Correct |
51 ms |
12872 KB |
Output is correct |
9 |
Correct |
52 ms |
12872 KB |
Output is correct |
10 |
Correct |
50 ms |
12816 KB |
Output is correct |