[Python] 백준(baekjoon) 10815 숫자카드

YoungSeob So·2022년 11월 10일
0

Algorithm

목록 보기
1/2
post-thumbnail
The Gardener Vallier (1906)

[10815]숫자카드


> 💡문제접근

❌ 이중 for문을 통한 완전탐색(시간초과)
❌ 오름차순 후 완전탐색(시간초과)
🙆‍♂️ Set
🙆‍♂️ dictionary

> 🍕코드

1. Set

import sys
input = sys.stdin.readline

M = int(input())
card = set(list(map(int,input().split())))
N = int(input())
card2 = list(map(int, input().split()))

for i in card2:
    if i in card:
        print(1, end = ' ')
    else:
        print(0, end = ' ')

2. Dictionary

import sys
input = sys.stdin.readline

M = int(input())
card = list(map(int,input().split()))
N = int(input())
card2 = list(map(int, input().split()))

_dict = {}

for i in range(len(card)):
    _dict[card[i]] = 0

for j in range(N):
    if card2[j] in _dict:
        print(1, end = ' ')
    else:
        print(0, end = ' ')

0개의 댓글