Algorithm/문제풀이
[C++] 백준 알고리즘 14425번 문자열 집합
사과당근
2021. 9. 12. 20:17
이 문제는 1764 듣보잡 문제와 유사하다
대신 더 쉽다
왜냐하면 중복되는 문자열은 출력할 필요 없고
중복 갯수만 출력하면 되기 때문!
1764는 map, set을 이용했는데
이 문제는 map만 이용했다.
#include<iostream>
#include<map>
using namespace std;
int main() {
int n, m;
map<string, int> first;
string temp;
cin >> n >> m;
while (n--) {
cin >> temp;
first[temp] = 1;
}
int count = 0;
while (m--) {
cin >> temp;
if (first[temp] == 1)
count++;
}
cout << count << '\n';
}
출력 결과 잘 나온다