본문 바로가기
이론/코딩테스트

[백준] 1764번 듣보잡 (맵)

by 퇴근후개발 2022. 8. 3.
반응형

-문제

 

-코드

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

int main()
{
	int n, m;
	cin >> n >> m;
	map<string, int> map;
	vector<string> res;

	for (int i = 0; i < n+m; i++)
	{
		string tmp;
		cin >> tmp;
		map[tmp]++;
		if (map[tmp] > 1) res.push_back(tmp);
	}
	sort(res.begin(), res.end());
	cout << res.size() << '\n';
	for (int i = 0; i < res.size(); i++)
	{
		cout << res[i] << '\n';
	}
	return 0;
}

 

반응형