# BaekJoon 1764 듣보잡

문제 출처 (opens new window)

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(void){

    ios::sync_with_stdio(false);
	cin.tie(NULL);
	
    int N, M;
	cin >> N >> M;
	vector<string> a;
	vector<string> b;
	vector<string> answer(N+M);
	vector<string>::iterator iter;
    for(int i=0; i<N; i++){
		string tmp;
        cin >> tmp;
		a.push_back(tmp);
    }
    for(int i=0; i<M; i++){
		string tmp;
        cin >> tmp;
		b.push_back(tmp);
    }

    sort(a.begin(), a.end());
    sort(b.begin(), b.end()); 
	
	iter = set_intersection(a.begin(), a.end(), b.begin(), b.end(), answer.begin());
    answer.resize(iter - answer.begin());
	sort(answer.begin(), answer.end());
	cout << answer.size() << "\n";
	for(int i=0; i<answer.size();i++){
		cout << answer[i] << "\n";
	} 
    return 0;
}