백준문제풀이
백준 문제 14425번 문자열 집합 문제풀이 c++
노가다 김씨
2022. 3. 22. 14:11
https://www.acmicpc.net/problem/14425
14425번: 문자열 집합
첫째 줄에 문자열의 개수 N과 M (1 ≤ N ≤ 10,000, 1 ≤ M ≤ 10,000)이 주어진다. 다음 N개의 줄에는 집합 S에 포함되어 있는 문자열들이 주어진다. 다음 M개의 줄에는 검사해야 하는 문자열들이 주어
www.acmicpc.net
문제해석
찾고자하는 문자열이 집합내에 있느냐를 판단하는것이니 map이나 set자료구조를 가져와서 find와 조합해서 쓰면된다.
set자료구조를 사용하여 코드를 작성했다.
코드
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
using namespace std;
set <string> s;
int main(){
cout.tie(NULL);
cin.tie(NULL);
ios_base::sync_with_stdio(false);
int n,m;
int ans=0;
string str;
cin>>n>>m;
for(int i=0; i<n; i++)
{
cin>>str;
s.insert(str);
}
for(int i=0; i<m; i++)
{
cin>>str;
if(s.find(str)!=s.end())
{
ans++;
}
}
cout<<ans;
}