본문 바로가기
카테고리 없음

[python] 백준 1920번 수 찾기

by _eunji_ 2021. 5. 5.

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]))

댓글