728x90
반응형
문제 출처: https://www.acmicpc.net/problem/10816
10816번: 숫자 카드 2
첫째 줄에 상근이가 가지고 있는 숫자 카드의 개수 N(1 ≤ N ≤ 500,000)이 주어진다. 둘째 줄에는 숫자 카드에 적혀있는 정수가 주어진다. 숫자 카드에 적혀있는 수는 -10,000,000보다 크거나 같고, 10,
www.acmicpc.net
풀이:
N = int(input())
arr = list(map(int, input().split()))
N2 = int(input())
arr2 = list(map(int, input().split()))
res = list()
for i in arr2:
if i in arr:
res.append(arr.count(i))
else:
res.append(0)
print(*res)
간단하게 풀었지마 바로 시간 초과로 틀렸다
n = int(input())
arr = list(map(int, input().split()))
dict = dict()
for i in arr:
if i in dict:
dict[i] += 1
else:
dict[i] = 1
m = int(input())
arr2 = list(map(int, input().split()))
for i in arr2:
if i in dict:
print(dict[i], end=' ')
else:
print(0, end=' ')
딕셔너리를 사용한 풀이.
반응형
댓글