17219번: 비밀번호 찾기
첫째 줄에 저장된 사이트 주소의 수 N(1 ≤ N ≤ 100,000)과 비밀번호를 찾으려는 사이트 주소의 수 M(1 ≤ M ≤ 100,000)이 주어진다. 두번째 줄부터 N개의 줄에 걸쳐 각 줄에 사이트 주소와 비밀번
www.acmicpc.net
풀이과정
map의 find 함수를 알게 해 준 문제이다.
res를 입력받고 res의 key값을 찾으면 그에 맞는 value를 출력해주면 된다.
#include <vector>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
using namespace std;
int N, M;
string adress, passwd, res;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL), cout.tie(NULL);
map <string, string> m;
cin >> N >> M;
while (N--) {
cin >> adress >> passwd;
m[adress] = passwd;
}
while (M--) {
cin >> res;
cout << m.find(res)->second << "\n";
}
}
'🍞 Problem Solving > Baekjoon' 카테고리의 다른 글
[백준] 2458 키 순서 c++ (0) | 2022.09.14 |
---|---|
[백준] 2910 빈도 정렬 c++ (0) | 2022.09.14 |
[백준] 5568 카드 놓기 c++ (0) | 2022.09.13 |
[백준] 14425 문자열 집합 c++ (0) | 2022.09.13 |
[백준] 1620 나는야 포켓몬 마스터 이다솜 c++ (0) | 2022.09.13 |