입력:
5
4 1 5 2 3
5
1 3 7 9 5
출력-->
1
1
0
0
1
백준 1920번 "수 찾기" 문제의 코드입니다.
#include <bits/stdc++.h>
using namespace std;
vector<int> a;
int main(void) {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int n;
cin>>n;
a.assign(n, 0); //0을 n개 가지는 벡터로.
for(int i=0; i<n; ++i)
cin>>a[i];
//binary_search를 사용하기 위해 정렬해야 함.
sort(a.begin(), a.end());
cin>>n;
for(int i=0; i<n; ++i) {
int key;
cin>>key;
if(binary_search(a.begin(), a.end(), key))
cout<<"1\n";
else
cout<<"0\n";
}
return 0;
}
위의 코드를 예제의 입력을 넣어 실행했을 때의 결과입니다.
백준 2468 안전 영역 C++ (0) | 2023.04.10 |
---|---|
백준 1181 단어 정렬 C++ (0) | 2023.04.07 |
백준 1260 DFS와 BFS C++ (0) | 2023.04.06 |
백준 1874 스택 수열 C++ (0) | 2023.04.06 |
백준 18111 마인크래프트 C++ (0) | 2023.04.06 |