반응형
https://www.acmicpc.net/problem/1764
- 문제
이름이 포함된 array가 두개 주어지면 둘 모두에 있는 이름을 출력한다.
- 해설
map<string,int>를 만들어서 두 개의 이름 집합에 대해서 ++해주면 2 이상인 이름이 듣도보도 못한 이름이 된다.
- 풀이
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
int main()
{
fastio;
int N, M;
string temp;
map<string, int> m;
vector<string> s;
s.reserve(N);
cin >> N >> M;
for (int i = 0; i < N; i++)
{
cin >> temp;
m[temp]++;
}
for (int i = 0; i < M; i++)
{
cin >> temp;
m[temp]++;
}
for (auto mm : m)
{
if (mm.second > 1)
s.push_back(mm.first);
}
cout << s.size() << '\n';
for (auto ss : s)
{
cout << ss << '\n';
}
return 0;
}
- 새롭게 알게 된 점
#define fastio 이런 방식으로 사람들이 많이 만들길래, 한 번 따라해봤다.
반응형
'Algorithm > Baekjoon BOJ' 카테고리의 다른 글
[백준][C++] 11478 : 서로 다른 부분 문자열의 개수 (0) | 2022.10.21 |
---|---|
[백준][C++] 1269 : 대칭 차집합 (0) | 2022.10.21 |
[백준][C++] 10816 : 숫자 카드 2 (0) | 2022.10.14 |
[백준][C++] 1620 : 나는야 포켓몬 마스터 이다솜 (0) | 2022.10.14 |
[백준][C++] 10815 : 숫자 카드 (0) | 2022.10.13 |