백준 1620 포켓몬 마스터

CJB_ny·2023년 1월 1일
0

백준

목록 보기
30/104
post-thumbnail

포켓몬 마스터

#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;
}

분석 및 후기

atoi()

입력받은 문자열이 정수면 정수로 return
문자라면은 0을 return

atoi를 사용해서 구현하는 문제이다.

c_str()

string객체를 *char로 변경해주는 함수

c_str()

위의 링크에서

profile
https://cjbworld.tistory.com/ <- 이사중

0개의 댓글