백준 1620 c++
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <cctype>
using namespace std;
int input(int lower, int upper);
void input_list(map<string, int>& pokemon, string* pokemon_name, int N);
void input_question(string* question, int M);
void find_print_answer(map<string, int>& pokemon, string* pokemon_name, int N, string* question, int M);
int main(void)
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int N, M;
map<string, int> pokemon;
string* pokemon_name;
string* question;
N = input(1, 100000);
M = input(1, 100000);
pokemon_name = new string[N + 1];
question = new string[M + 1];
input_list(pokemon, pokemon_name, N);
input_question(question, M);
find_print_answer(pokemon, pokemon_name,N, question, M);
delete[] pokemon_name;
delete[] question;
return 0;
}
int input(int lower, int upper)
{
int A;
while (1)
{
cin >> A;
if (A >= lower && A <= upper)
{
break;
}
else
{
;
}
}
return A;
}
void input_list(map<string, int> &pokemon, string* pokemon_name, int N)
{
int i;
string temp;
for (i = 1; i <= N; i++)
{
cin >> temp;
pokemon_name[i] = temp;
pokemon.insert(make_pair(temp, i));
}
return;
}
void input_question(string* question, int M)
{
int i;
string temp;
for (i = 1; i <= M; i++)
{
cin >> temp;
question[i] = temp;
}
return;
}
void find_print_answer(map<string, int>& pokemon, string* pokemon_name, int N, string* question, int M)
{
int i;
int temp;
string temp_str;
for (i = 1; i <= M; i++)
{
temp_str = question[i];
//cout << "temp_str : " << temp_str << endl;
//cout << "isdigit결과 : " << isdigit(temp_str[0]) << endl;
if (isdigit(temp_str[0]))
{
//cout << temp_str << endl;
temp = stoi(temp_str);
cout << pokemon_name[temp] << "\n";
}
else
{
//cout << temp_str << endl;
auto it = pokemon.find(temp_str);
cout << it->second << "\n";
}
}
return;
}