HJW's IT Blog

[BOJ][C++][Python] 17219번: 비밀번호 찾기 본문

Algorithm

[BOJ][C++][Python] 17219번: 비밀번호 찾기

kiki1875 2023. 3. 31. 18:21

Python의 경우 딕셔너리 자료형을 이용하여 직접 key로 접근하였고

C++의 경우 Map 자료구조를 이용하였다.

 

python

import sys
input = sys.stdin.readline
lst = {}

N, M = map(int,input().split())


for i in range(N):
    temp1, temp2 = map(str,input().split())
    lst[temp1] = temp2

for i in range(M):
    web = input()
    length = len(web)
    print(lst[web[0:length-1]])

 

C++

#include <iostream>
#include <map>

using namespace std;

int main() {
    cin.tie(NULL);
    ios::sync_with_stdio(false);

    map<string,string>m;

    int N, M;
    string st1, st2;
    
    cin >> N >> M;



    while(N--){
        cin >> st1 >> st2;
        m.insert(make_pair(st1,st2));
    }
    while(M--){
        cin >> st1;
        cout << m[st1]<< "\n";
    }

    return 0;
}