https://www.acmicpc.net/problem/1620
#include <bits/stdc++.h>
#include <unordered_map>
#define endl "\n"
using namespace std;
int main(void) {
// C++ Init
ios::sync_with_stdio(false);
cin.tie(NULL);
int input1, input2;
string str;
unordered_map<string, int> um;
vector<string> v;
cin >> input1 >> input2;
for (int i = 0; i < input1; i++) {
cin >> str;
um.insert({ str, i + 1 });
v.push_back(str);
}
for (int i = 0; i < input2; i++) {
cin >> str;
if (isdigit(str[0])) {
cout << v[stoi(str) - 1] << endl;
}
else cout << um[str] << endl;
}
}
'알고리즘' 카테고리의 다른 글
C++ 알고리즘 - 백준 11047 동전 0 (0) | 2025.01.04 |
---|---|
C++ 알고리즘 - 백준 1764 듣보잡 (unordered_map) (0) | 2025.01.04 |
C++ 알고리즘 - 백준 11723 집합 (0) | 2025.01.04 |
C++ 알고리즘 - 백준 1654 랜선 자르기 (이분/매개변수 탐색) (0) | 2025.01.04 |
C++ 알고리즘 - 백준 2108 통계학 (0) | 2025.01.04 |