1620번: 나는야 포켓몬 마스터 이다솜(20분)

myeongrangcoding·2023년 12월 5일
0

백준

목록 보기
12/47

https://www.acmicpc.net/problem/1620

구현 아이디어 5분 구현 15분

풀이

endl -> 'n\'.

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <unordered_map>

using namespace std;

int main() {
    //freopen("input.txt", "rt", stdin);

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int N{}, M{};
    cin >> N >> M;

    string PocketmonName{};
    unordered_map<string, int> MapPocketmons;
    vector<string> VecPocketmons(N + 1);

    for (int ix = 1; ix <= N; ++ix)
    {
        cin >> PocketmonName;
        MapPocketmons.insert(make_pair(PocketmonName, ix));
        VecPocketmons[ix] = PocketmonName;
    }

    string Question;
    for (int ix = 0; ix < M; ++ix)
    {
        cin >> Question;

        if (Question[0] >= '0' && Question[0] <= '9')
        {
            cout << VecPocketmons[stoi(Question)] << '\n';
        }
        else
        {
            cout << MapPocketmons[Question] << '\n';
        }
    }

    return 0;
}
profile
명랑코딩!

0개의 댓글