
#include <iostream>
#include <algorithm>
using namespace std;
int main(int argc, char **argv){
int N, M, x;
scanf("%d", &N); // 상근이의 카드 개수
int * sang = new int[N];
for(int i=0; i<N; i++){
scanf("%d", &sang[i]);
}
sort(sang, sang + N); // 정렬
scanf("%d", &M); // 판단 수
for(int i=0; i<M; i++){
scanf("%d", &x);
if(binary_search(sang, sang + N, x)){
printf("1 ");
} else {
printf("0 ");
}
}
return 0;
}
오늘의 키포인트
- 이진 탐색을 STL을 써서 구현해보았다. 훨씬 깔끔하고 간단해서 좋다.
https://ryute.tistory.com/33 를 참고하여 알고리즘 공부를 진행중인데, 해당 문제에서 무엇을 알고 가면 좋을지를 알려주셔서 좋다. 이렇게 binary_search 를 활용해서 깔끔하게 문제를 풀 수 있었다. 굿.