# 생각
string과 int가 key일 때 각각의 map을 사용하여 해결 가능하다
atoi는 문자를 만나면 0을 return하는 것을 이용하여 문자인지 숫자인지 판단해준다
# 전체 코드
#include <bits/stdc++.h>
using namespace std;
void fastIO() { ios::sync_with_stdio(false); cin.tie(nullptr); }
int main()
{
fastIO();
int n, m;
cin >> n >> m;
map<string, int> m1;
map<int, string> m2;
for (int i = 0; i < n; i++)
{
string s;
cin >> s;
m1[s] = i + 1;
m2[i + 1] = s;
}
for (int i = 0; i < m; i++)
{
string s;
cin >> s;
if (atoi(s.c_str()) == 0)
{ // 문자일때(atoi는 문자를 만나면 0을 return)
cout << m1[s] << '\n';
}
else
{ // 숫자일때
cout << m2[atoi(s.c_str())] << '\n';
}
}
}
https://www.acmicpc.net/problem/1620
'Algorithm > BOJ' 카테고리의 다른 글
[BOJ] 1213_팰린드롬 만들기.cpp (0) | 2022.05.30 |
---|---|
[BOJ] 9375_패션왕 신해빈.cpp (0) | 2022.05.30 |
[BOJ] 2559_수열.cpp (0) | 2022.05.29 |
[BOJ] 9996_한국이 그리울 땐 서버에 접속하지.cpp (0) | 2022.05.29 |
[BOJ] 11655_ROT 13.cpp (0) | 2022.05.28 |