File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed
weekly/week01/BOJ_1920_수 찾기 Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments