728x90
반응형
1620번 나는야 포켓몬 마스터 이다솜
문제
문제 풀이
#include <iostream>
#include <string.h>
#include <map>
using namespace std;
void fast_io(void)
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
int main(void)
{
fast_io();
map<int, string> mpInt;
map<string, int> mpStr;
int n, m, idx = 0;
cin >> n >> m;
while (n--)
{
idx++;
string str;
cin >> str;
mpInt.insert(make_pair(idx, str));
mpStr.insert(make_pair(str, idx));
}
while (m--)
{
char arr[21];
cin >> arr;
if (isdigit(arr[0]))
{
int intArr = atoi(arr);
cout << mpInt.find(intArr)->second << "\n";
}
else
{
cout << mpStr.find(arr)->second << "\n";
}
}
}
벡터로 하다가 알고리즘분류에 맵이 있어서 맵으로 했다.
한개의 맵에서 키 로 밸류찾기 , 밸류로 키 찾기를 하고싶었으나 어려움이 있어서 두개를 만들었다.
728x90
반응형
'자라는 개발자 > 문제풀이' 카테고리의 다른 글
백준 C++ 10809 알파벳 찾기 (0) | 2022.01.05 |
---|---|
백준 C++ 17219번 비밀번호 찾기 (8) | 2022.01.04 |
백준 C++/C 2577번 숫자의 개수 (1) | 2021.12.27 |
백준 C++ 1764번 듣보잡 (1) | 2021.12.26 |
백준 C/C++ 11050번 이항 계수 1 (0) | 2021.12.23 |