Skip to content

Commit 2020c85

Browse files
committed
[Week01] BOJ 1920: 수 찾기
1 parent daa039a commit 2020c85

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include <iostream>
2+
#include <algorithm>
3+
using namespace std;
4+
5+
int n, m, num;
6+
int a[100001];
7+
8+
bool find(int num, int l, int r) {
9+
while(l <= r) {
10+
int mid = (l + r) / 2;
11+
if(num == a[mid]) {
12+
return true;
13+
}
14+
else if(num > a[mid]) {
15+
l = mid + 1;
16+
}
17+
else {
18+
r = mid - 1;
19+
}
20+
}
21+
return false;
22+
}
23+
24+
int main() {
25+
ios_base::sync_with_stdio(false);
26+
cin.tie(NULL); cout.tie(NULL);
27+
28+
cin >> n;
29+
for(int i = 0; i < n; i++) {
30+
cin >> a[i];
31+
}
32+
sort(a, a + n);
33+
cin >> m;
34+
for(int i = 0; i < m; i++) {
35+
cin >> num;
36+
if(find(num, 0, n - 1)) {
37+
cout << 1 << '\n';
38+
}
39+
else {
40+
cout << 0 << '\n';
41+
}
42+
}
43+
return 0;
44+
}

0 commit comments

Comments
 (0)