[1764] 듣보잡

yyeahh·2021년 3월 12일
0

Baekjoon

목록 보기
6/19

[1764] 듣보잡

ios_base::sync_with_stdio(false); 
cin.tie(NULL); 
cout.tie(NULL);
- 위와 같은 c++에서 입출력에 걸리는 시간을 단축하기 위해 사용하는 편법을 사용할 때는 c의 scanf/printf와 혼용하지 않게 주의해야한다.
- 입출력이 원하지 않게 순서가 뒤바뀔 수 있기 때문이다.
bool binary_search(시작, 끝, 비교할 문자열) {}
이미 정렬된 데이터만 파라미터에 집어넣을 수 있다.
(find함수를 사용했을 때 time over가 발생)
[2021.03.13]
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

	int N, M;
	string name;

	cin >> N >> M;
	vector<string> heard(N), answer;
	for (int i = 0; i < N; i++) cin >> heard[i]; sort(heard.begin(), heard.end());
	for (int i = 0; i < M; i++) {
		cin >> name;
		if (binary_search(heard.begin(), heard.end(), name)) answer.push_back(name);
		//bool binary_search(시작, 끝, 비교할 문자열) : 이미 정렬된 데이터만 파라미터에 집어넣을 수 있음
	}
	sort(answer.begin(), answer.end());

	cout << answer.size() << endl;
	for (string i : answer) cout << i << endl;
}

0개의 댓글