728x90
반응형
1764번 듣보잡
문제풀이
#include <iostream>
#include <vector>
#include <string.h>
#include <algorithm>
using namespace std;
void fast_io(void)
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
int main(void)
{
fast_io();
vector<string> ear;
vector<string> res;
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++)
{
string str;
cin >> str;
ear.push_back(str);
}
sort(ear.begin(), ear.end());
for (int i = 0; i < m; i++)
{
string str;
cin >> str;
if (binary_search(ear.begin(), ear.end(), str))
{
res.push_back(str);
}
}
sort(res.begin(), res.end());
cout << res.size() << "\n";
for (int i = 0; i < res.size(); i++)
{
cout << res.at(i) << "\n";
}
}
듣보명단 받은 뒤, 들어오는 명단과 비교해서 res에 넣어주고 사전순으로 출력해줬다.
binary_search(시작, 끝, 찾는값) 사용했다.
728x90
반응형
'자라는 개발자 > 문제풀이' 카테고리의 다른 글
백준 c++ 1620 나는야 포켓몬 마스터 이다솜 (1) | 2022.01.02 |
---|---|
백준 C++/C 2577번 숫자의 개수 (1) | 2021.12.27 |
백준 C/C++ 11050번 이항 계수 1 (0) | 2021.12.23 |
백준 C++ 11651번 좌표정렬하기 2 (0) | 2021.12.22 |
백준 C++ 1654번 랜선 자르기 (0) | 2021.12.21 |