Little Jay

[C++] 백준 17219번 - 비밀번호 찾기 본문

알고리즘/BOJ

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

Jay, Lee 2021. 8. 16. 15:44

map을 이용해서 풀면 간단히 해결할 수 있는 문제

linux 채점환경이기때문에 시간초과가 나지 않으려면 

ios::sync_with_stdio(false);
cin.tie(0);

를 추가해주어야 한다

 

#include <iostream>
#include <string>
#include <map>
using namespace std;

int main() {

	ios::sync_with_stdio(false);
	cin.tie(0);

	int n, m;
	cin >> n >> m;

	string site, pw;
	map<string, string> mp;

	for (int i = 0; i < n; i++) {
		cin >> site >> pw;
		mp.insert(pair<string, string>(site, pw));
	}

	for (int i = 0; i < m; i++) {
		cin >> site;

		cout << mp.find(site)->second << "\n";
	}


	return 0;
}

'알고리즘 > BOJ' 카테고리의 다른 글

[C++] 백준 11399번 - ATM  (0) 2021.08.16
[C++] 백준 1463번 - 1로 만들기  (0) 2021.08.16
[C++] 백준 11723번 - 집합  (0) 2021.08.14
[C++] 백준 2417번 - 정수 제곱근  (0) 2021.08.08
[C++] 백준 13777번 - Hunt The Rabbit  (0) 2021.08.08
Comments