# BaekJoon 1620 나는야 포켓몬 마스터 이다솜

문제 출처 (opens new window)

  • 풀이 코드 :
#include <iostream>
#include <unordered_map>
using namespace std;

int main(void){

    ios::sync_with_stdio(false);
	cin.tie(NULL);
    cout.tie(NULL);
	
    int N, M;
	cin >> N >> M;
	unordered_map <string,int> a;    
	string b[N+1];
    for(int i=0; i<N; i++){
		string tmp;
        cin >> tmp;
		a.insert({tmp,i+1});
		b[i+1]=tmp;
    }

	for(int i=0; i<M; i++){
		string tmp;
        cin >> tmp;
		if (isdigit(tmp[0])) {
			int tmpint=stoi(tmp);
			cout << b[tmpint];  // tmp is number
		}
		else{
			cout << a.find(tmp)->second;  // tmp is name
		}
		cout << "\n";
    }
    
    return 0;
}