728x90
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
int n,m;
cin>>n>>m;
set<string> s;
set<string> output;
for (int i = 0; i < n; i++)
{
string input;
cin>>input;
s.insert(input);
}
for (int i = 0; i < m; i++)
{
string tofind;
cin>>tofind;
if(s.find(tofind)!=s.end()){
output.insert(tofind);
}
}
cout<<output.size()<<"\n";
for(auto& str : output)
{
cout<<str<<"\n";
}
return 0;
}
처음에 헤더 파일에 cstdio를 포함해서 printf를 하려니 오류가 생겨서 이유를 알아보니 printf를 사용하려면 string이 아니라 char*로 사용해야 한다고 했다.
string class를 사용하기 위해서 헤더를 수정하고 출력방식도 바꿨다.
728x90
'BOJ' 카테고리의 다른 글
<11404번> 플로이드 (0) | 2021.12.01 |
---|---|
<10026번> 적록색약 (0) | 2021.12.01 |
<1654번> 랜선 자르기 (0) | 2021.12.01 |
<1158번> 요세푸스 문제 (0) | 2021.12.01 |
<1920번> 수 찾기 (0) | 2021.11.30 |