728x90
반응형
단순 구현
#include <iostream>
#include <unordered_set>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int N, M;
cin >> N >> M;
unordered_set<string> names;
vector<string> ans;
int count = 0;
for (int i = 0; i < N; i++)
{
string unheard_name;
cin >> unheard_name;
names.insert(unheard_name);
}
for (int i = 0; i < M; i++)
{
string unseened_name;
cin >> unseened_name;
if (names.count(unseened_name))
{
ans.push_back(unseened_name);
count++;
}
}
sort(ans.begin(), ans.end());
cout << count << endl;
for (const string &name : ans)
{
cout << name << endl;
}
return 0;
}
728x90
반응형
'Baekjoon > Silver' 카테고리의 다른 글
Baekjoon 17219.비밀번호 찾기 c++ [Silver IV] (0) | 2024.12.23 |
---|---|
Baekjoon 11399.ATM c++[Silver IV] (0) | 2024.12.22 |
Baekjoon 11723.집합 c++ [Silver V] (0) | 2024.12.13 |
Baekjoon 1874.스택 수열 c++ [Silver II] (0) | 2024.12.09 |
Baekjoon 2839.ŠEĆER c++ [Silver IV] (1) | 2024.12.09 |