0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-05 02:26:26 +00:00
OI-codes/AtCoder/ABC219/C/C.cpp

34 lines
637 B
C++

#include <bits/stdc++.h>
using namespace std;
int n;
map<char, int> m;
string a, s[50005];
int main() {
std::ios::sync_with_stdio(false);
cin >> a;
for (int i = 0; i < a.size(); i++) {
m[a[i]] = i;
}
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s[i];
}
sort(s, s + n, [](string a, string b) {
string aa, bb;
for (char c : a) {
aa.push_back(m[c] + 'a');
}
for (char c : b) {
bb.push_back(m[c] + 'a');
}
return aa < bb;
});
for (int i = 0; i < n; i++) {
cout << s[i] << endl;
}
return 0;
}