-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathN10815.cpp
36 lines (33 loc) · 839 Bytes
/
N10815.cpp
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
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
int isInCard(int,int *,int,int);
int main(){
int n ;
scanf("%d",&n);
int *myCard = (int *)malloc(sizeof(int)*n);
for(int i = 0;i<n;i++)
scanf("%d",&myCard[i]);
int k;
scanf("%d",&k);
int *card = (int *)malloc(sizeof(int)*k);
for(int i = 0; i<k;i++)
scanf("%d",&card[i]);
sort(card,card+k);
for(int i = 0;i<n;i++){
printf("%d ",isInCard(myCard[i],card,0,n-1));
}
return 0;
}
int isInCard(int card,int *cardList,int s,int e){
int mid = (s+e)/2;
if (card == cardList[mid])
return 1;
if (e<s)
return 0;
if(card>cardList[mid])
return isInCard(card,cardList,mid+1,e);
if(card<cardList[mid])
return isInCard(card,cardList,s,mid-1);
}