We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents baf8e0f + 2020c85 commit 6166fafCopy full SHA for 6166faf
1 file changed
weekly/week01/BOJ_1920_수 찾기/gyuhyeok99.cpp
@@ -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
40
+ cout << 0 << '\n';
41
42
43
+ return 0;
44
0 commit comments