-
Notifications
You must be signed in to change notification settings - Fork 0
/
6주차_과제3(10815).c
54 lines (52 loc) · 1.01 KB
/
6주차_과제3(10815).c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
typedef struct
{
int value;
int rank;
}na;
int compare(const void* a, const void* b)
{
na num1 = *(na*)a;
na num2 = *(na*)b;
if (num1.value < num2.value)
return -1;
if (num1.value > num2.value)
return 1;
return 0;
}
int binarysearch(na a[], int count, int num)
{
int left = 0;
int right = count - 1;
int mid;
while (left <= right) {
mid = (left + right) / 2;
if (a[mid].value == num)
return 1;
if (a[mid].value < num)
left = mid + 1;
else
right = mid - 1;
}
return 0;
}
na a[500000] = { 0 }, b[500000] = { 0 };
int main()
{
int case_num1, case_num2;
scanf("%d", &case_num1);
for (int i = 0; i < case_num1; i++)
scanf("%d", &a[i].value);
scanf("%d", &case_num2);
for (int i = 0; i < case_num2; i++)
scanf("%d", &b[i].value);
qsort(a, case_num1, sizeof(na), compare);
for (int i = 0; i < case_num2; i++) {
int k = binarysearch(a, case_num1, b[i].value);
printf("%d ", k);
}
}