No Rules Rules

문자열 집합 (feat. 백준, 14425번) 본문

생활/코테

문자열 집합 (feat. 백준, 14425번)

개발하는 완두콩 2022. 8. 3. 12:11
728x90
반응형

문자열 집합
https://www.acmicpc.net/problem/14425

 

14425번: 문자열 집합

첫째 줄에 문자열의 개수 N과 M (1 ≤ N ≤ 10,000, 1 ≤ M ≤ 10,000)이 주어진다.  다음 N개의 줄에는 집합 S에 포함되어 있는 문자열들이 주어진다. 다음 M개의 줄에는 검사해야 하는 문자열들이 주어

www.acmicpc.net

반응형
// woohyeon.kim
// https://www.acmicpc.net/problem/14425
#include <iostream>
#include <set>
using namespace std;
int main() {
	ios::sync_with_stdio(false), cin.tie(NULL);
	register int N, M, ans = 0;
	string tmp;
	set<string> S;
	cin >> N >> M;
	for (register int i = 0; i < N; ++i)
		cin >> tmp, S.insert(tmp);
	for (register int i = 0; i < M; ++i) {
		cin >> tmp;
		if (S.find(tmp) != S.end())
			++ans;
	}
	cout << ans;
	return 0;
}
// *&)*@*

자료구조 set을 이용해서 검사할 문자열과 동일한 문자열이 있을 경우, 정답의 개수를 +1 해줍니다.

728x90
반응형
Comments