본문 바로가기
CS(Computer Science)지식/[C++][코딩 테스트] 자료구조 및 알고리즘

백준 17219번: 비밀번호 찾기 [C++]

by 엔지니어 청년 2024. 1. 31.

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

#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;


int n,m;
unordered_map<string, string> um;

int main()
{
    cin >> n >> m;

    for(int i=0; i< n ;i++)
    {
        string add;
        string pass;
        cin >> add >> pass;
        um.insert(make_pair(add,pass));
    }

    for(int i=0;i<m;i++)
    {
        string add;
        cin >> add;
        if(um.find(add)!=um.end())cout << um[add] << '\n';
    }

}

바킹독님 풀이

// Authored by : heheHwang
// Co-authored by : -
// http://boj.kr/6dbb1711d18a41e48fa54edfcb93cc7c
#include 
using namespace std;

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

  int N, M;
  string s, p;
  unordered_map<string, string=""> umap;

  cin >> N >> M;
  while (N--) {
    cin >> s >> p;
    umap[s] = p;
  }
  while (M--) {
    cin >> s;
    cout << umap[s] << '\n';
  }
}</string,>