이 문제는 hashSet을 사용하여 푸는 간단한 문제이다.
문제해결방법
1. 먼저 집합 S를 입력받는다.
2. M개의 문자열을 입력받고 집합 S에 포함되는지 확인한다. 만약 있다면 count++를 해준다.
3. count를 출력한다.
#include <iostream>
#include <unordered_set>
using namespace std;
int main(void)
{
unordered_set<string> hashSet;
int N = 0;
int M = 0;
cin >> N >> M;
for (int i = 0; i < N; i++)//집합 S를 입력받음.
{
string temp = "";
cin >> temp;
hashSet.insert(temp);
}
int count = 0;
for (int i = 0; i < M; i++)//집합 S에 포함되는가??
{
string temp = "";
cin >> temp;
if (hashSet.find(temp) != hashSet.end())
{
count++;
}
}
cout << count;
return 0;
}
'백준 > 해시' 카테고리의 다른 글
[백준] C++ 2002번 추월 (0) | 2024.09.29 |
---|---|
[백준] C++ 4358번 생태학 (0) | 2024.09.29 |
[백준] C++ 20920번 영단어 암기는 괴로워 (1) | 2024.09.28 |
[백준] C++ 11478번 서로 다른 부분 문자열의 개수 (1) | 2024.09.28 |
[백준] C++1764 듣보잡 (2) | 2024.09.25 |