[백준] 1620 나는야 포켓몬 마스터 이다솜
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int N, M;
cin >> N >> M;
map <int, string> numToName;
map <string, int> nameToNum;
for (int i = 0; i < N; ++i) {
string name;
cin >> name;
numToName[i + 1] = name;
nameToNum[name] = i + 1;
}
for (int i = 0; i < M; ++i) {
string input;
cin >> input;
if (nameToNum.find(input) != nameToNum.end()) {
cout << nameToNum[input] << "\n";
}
else {
int num = stoi(input);
cout << numToName[num] << "\n";
}
}
return 0;
}