백준
[백준] 10815번 : 숫자 카드 - 파이썬(Python) - 우당탕탕 개발자 되기 프로젝트
우당탕탕 개발자
2023. 11. 18. 13:21
728x90
반응형

10815번: 숫자 카드
첫째 줄에 상근이가 가지고 있는 숫자 카드의 개수 N(1 ≤ N ≤ 500,000)이 주어진다. 둘째 줄에는 숫자 카드에 적혀있는 정수가 주어진다. 숫자 카드에 적혀있는 수는 -10,000,000보다 크거나 같고, 10,
www.acmicpc.net
1. 문제 설명

2. 풀이과정
해당 문제는 입력받은 가지고 있는 숫자 카드의 정수를 리스트보다 빠른 딕셔너리에 저장하여 구별할 숫자 카드의 정수를 하나씩 불러와 가지고 있는지 비교한다.
- sys.stdin.readline() 함수를 사용하기 위해 sys 모듈을 불러온다. import sys
- 가지고 있는 숫자 카드의 개수를 입력받는다. N = int(sys.stdin.readline())
- 가지고 있는 숫자 카드에 적혀있는 정수를 입력받아 리스트로 저장한다. card = list(map(int, sys.stdin.readline().split()))
- 구별할 숫자 카드의 개수를 입력받는다. M = int(sys.stdin.readline())
- 구별할 숫자 카드에 적혀있는 정수를 입력받아 리스트로 저장한다. check = list(map(int, sys.stdin.readline().split()))
- 가지고 있는 카드를 저장할 딕셔너리를 생성하고 d = {}
- 가지고 있는 카드를 딕셔너리에 저장한다. for i in card: d[i] = 0
- 구별할 숫자 카드를 하나씩 불러오며 for i in check
- 해당 카드가 딕셔너리에 있으면 1을 출력하고 if (i in d): print(1, end=' ')
- 딕셔너리에 없으면 0을 출력한다. else: print(0, end=' ')
반응형
3. 소스코드
import sys
N = int(sys.stdin.readline())
card = list(map(int, sys.stdin.readline().split()))
M = int(sys.stdin.readline())
check = list(map(int, sys.stdin.readline().split()))
d = {}
for i in card:
d[i] = 0
for i in check:
if (i in d):
print(1, end=' ')
else:
print(0, end=' ')
728x90
반응형