#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl "\n";
int N, M;
map<string, int> m;
string arr[100001];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> N >> M;
string str;
for (int i = 1; i <= N; ++i)
{
cin >> str;
m[str] = i;
arr[i] = str;
}
for (int i = 1; i <= M; ++i)
{
cin >> str;
if (atoi(str.c_str()) == 0)
{
cout << m[str] << endl;
}
else
{
cout << arr[atoi(str.c_str())] << endl;
}
}
system("pause");
return 0;
}
입력받은 문자열이 정수면 정수로 return
문자라면은 0을 return
atoi를 사용해서 구현하는 문제이다.
string객체를 *char로 변경해주는 함수
위의 링크에서