나의 브을로오그으

[c++] 1620번 : 나는야 포켓몬 마스터 이다솜 본문

알고리즘/BaekJoon

[c++] 1620번 : 나는야 포켓몬 마스터 이다솜

__jhp_+ 2022. 6. 12. 18:20

https://www.acmicpc.net/problem/1620

 

1620번: 나는야 포켓몬 마스터 이다솜

첫째 줄에는 도감에 수록되어 있는 포켓몬의 개수 N이랑 내가 맞춰야 하는 문제의 개수 M이 주어져. N과 M은 1보다 크거나 같고, 100,000보다 작거나 같은 자연수인데, 자연수가 뭔지는 알지? 모르면

www.acmicpc.net

#include <iostream>
#include <unordered_map>
#include <string>
using namespace std;

bool isNumber(const char* str)
{
	int dist = str[0] - '0';
	return 0 <= dist && dist <= 9;
}

string strArr[100001];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);

	int N, M;
	cin >> N >> M;

	string name;
	unordered_map<string, int> books;
	for (int i = 1; i <= N; ++i)
	{
		cin >> name;

		books.insert(make_pair(name, i));
		strArr[i] = name;
	}

	for (int i = 0; i < M; ++i)
	{
		string input;
		cin >> input;
		if (isNumber(input.c_str()) == true)
		{
			int num = stoi(input);
			cout << strArr[num] << '\n';
		}
		else
		{
			cout << books[input] << '\n';
		}
	}

	return 0;
}