본문 바로가기

Coding/BaekJoon

B_1620

#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

map<string, int> dictionary;

static bool comp(pair<string, int> &a, pair<string, int> &b)
{
    return a.second < b.second;
}

int searchDict(string name)
{
    return dictionary.find(name)->second;
}

int main(void)
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int N, M;
    cin >> N >> M;
    for (int i = 1; i <= N; i++)
    {
        string temp;
        cin >> temp;
        dictionary.insert({temp, i});
    }

    vector<pair<string, int>> dicVec(dictionary.begin(), dictionary.end());
    sort(dicVec.begin(), dicVec.end(), comp);

    for (int i = 1; i <= M; i++)
    {
        string temp;
        cin >> temp;
        if (temp[0] < 65)
        {
            int num = stoi(temp);
            cout << dicVec[num - 1].first << '\n';
        }
        else
        {
            cout << searchDict(temp) << '\n';
        }
    }
}

'Coding > BaekJoon' 카테고리의 다른 글

B_1934  (0) 2023.11.17
B_11478  (0) 2023.11.17
B_7785  (0) 2023.11.17
B_10989  (0) 2023.09.26
B_24313  (0) 2023.09.26