BOJ
[BOJ 13211 // C++] Passport Checking
measurezero
2023. 6. 1. 10:00
※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※
이번에 볼 문제는 백준 13211번 문제인 Passport Checking이다.
문제는 아래 링크를 확인하자.
https://www.acmicpc.net/problem/13211
13211번: Passport Checking
The first line of the input contains an integer N. (1 ≤ N ≤ 100,000) The next N lines contains the list of N stolen passport numbers, one passport number per line. The next line of the input contains an integer M. (1 ≤ M ≤ 100,000) The next M lines
www.acmicpc.net
주어진 N개의 문자열이 주어질 때, M개의 각 문자열이 N개의 문자열 중 하나와 같은지를 판단하는 문제이다. 이는 set을 이용하여 간단히 해결할 수 있다.
구체적으로, N개의 문자열을 set에 집어넣고, M개의 각 문자열이 set에 포함되어있는지를 확인해 문제를 해결하자.
아래는 제출한 소스코드이다.
#include <iostream>
#include <set>
#include <string>
using namespace std;
int N, M, ans;
set<string> st;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> N;
while (N--) {
string s; cin >> s;
st.insert(s);
}
cin >> M;
while (M--) {
string s; cin >> s;
if (st.count(s)) ans++;
}
cout << ans;
}
728x90