자라는 개발자/문제풀이

백준 C++ 17219번 비밀번호 찾기

자란다 2022. 1. 4. 20:51
728x90
반응형

17219 번 비밀번호 찾기


문제풀이

#include <iostream>
#include <string.h>
#include <map>
#include <sstream>
using namespace std;
void fast_io(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
string c, d;
int main(void)
{
    fast_io();
    map<string, string> m;
    int a, b;
    cin >> a >> b;
    cin.ignore();
    while (a--)
    {
        string all;
        getline(cin, all);
        stringstream ss(all);
        ss >> c >> d;
        m.insert(make_pair(c, d));
    }
    while (b--)
    {
        cin >> c;
        cout << m.find(c)->second << "\n";
    }
}

원래 stringstream 을 안쓰고 했는데 써봤다.
받은string을 공백이나 개행단위로 끊어서 ss에 저장하고
c 와 d 로 넘겨주었다.

728x90
반응형