[백준] 17219번 비밀번호 찾기 / C++
#문제
#풀이
#include <iostream>
#include <string>
#include <unordered_map>
using namespace std;
unordered_map<string, string> addressBook;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
while (n--)
{
string address, password;
cin >> address >> password;
addressBook.insert(make_pair(address, password));
}
while (m--)
{
string address;
cin >> address;
auto it = addressBook.find(address);
if (it != addressBook.end())
{
cout << it->second << '\n';
}
}
return 0;
}
#정리
검색 관련 문제는 알고리즘을 작성하기 쉬우나, 시간 초과 등의 문제가 발생하므로 해쉬로 접근하면 대부분 해결 가능.
Enjoy Reading This Article?
Here are some more articles you might like to read next: