
동일한 숫자 자리는 '1'이 아니면 '0'이 출력
코드를 입력하세요n = int(input("숫자 카드의 갯수 : "))
n_list = []
for i in range(n):
n_list.append(int(input()));
m = int(input("찾고자 하는 숫자 카드의 갯수 : "))
m_list = []
for i in range(m):
m_list.append(int(input()));
for idx in m_list:
if idx in n_list:
print(1, end=' ')
else:
print(0, end=' ')
내가 풀어본 코드
에러가 났다
알아보니 리스트를 쓰면 순차적으로 하나하나 다 돌아서 N X M 번을 돈다 하였다.
그래서 런타임 오류!!
import sys
# 한 줄씩 읽는 방식으로 변경
n = int(sys.stdin.readline())
n_cards = set(sys.stdin.readline().split()) # 바로 set으로 만들면 더 빠름!
m = int(sys.stdin.readline())
m_cards = sys.stdin.readline().split()
# 결과 비교
result = []
for card in m_cards:
if card in n_cards:
result.append("1")
else:
result.append("0")
print(" ".join(result))