https://www.acmicpc.net/problem/1920
1920번: 수 찾기
첫째 줄에 자연수 N(1 ≤ N ≤ 100,000)이 주어진다. 다음 줄에는 N개의 정수 A[1], A[2], …, A[N]이 주어진다. 다음 줄에는 M(1 ≤ M ≤ 100,000)이 주어진다. 다음 줄에는 M개의 수들이 주어지는데, 이 수들
www.acmicpc.net
def bin_search(a,key):
start=0
end=len(a)-1
while start<=end:
mid=(start+end)//2
if key==a[mid]:
return 1
elif key>a[mid]:
start= mid+1
else:
end=mid-1
if start > end:
return 0
n=int(input())
N=list(map(int,input().split()))
N.sort()
m=int(input())
M=list(map(int,input().split()))
for i in range(0,m):
print(bin_search(N,M[i]))
댓글