https://www.acmicpc.net/problem/1764
입출력
풀이
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
cout.tie(nullptr);
int n, m;
cin >> n >> m;
string noListen;
string noSee;
map<string, bool> names;
for (int i = 0; i < n; i++)
{
cin >> noListen;
names[noListen] = true;
}
vector<string> results;
for (int i = 0; i < m; i++)
{
cin >> noSee;
if (names[noSee])
results.push_back(noSee);
}
cout << results.size() << "\n";
sort(results.begin(), results.end());
for (int i = 0; i < results.size(); i++)
{
cout << results[i] << "\n";
}
}
이전 문제에서 map의 key 에 저장할 내용, value 에 bool 값을 true로 넣어서 풀었던 적이 있었다
똑같이 활용해서 풀면 된다
듣도 못한 사람의 이름들을 map의 key에 넣어주고 bool형 value에 true를 넣어준다
보도 못한 사람의 이름을 입력받고 해당 이름을 map 에서 찾았을 때 true라면
results벡터에 저장해놓고 출력한다.
'> 코딩테스트' 카테고리의 다른 글
[백준] 1269 대칭 차집합 (C++) (0) | 2023.06.17 |
---|---|
[백준] 11478 서로 다른 부분 문자열의 개수 (C++) (0) | 2023.06.15 |
[백준] 1620 나는야 포켓몬 마스터 이다솜 (C++) (0) | 2023.06.15 |
[백준] 14425 문자열 집합 (C++) (0) | 2023.06.13 |
[백준] 10815 숫자 카드 (C++) (1) | 2023.06.11 |