728x90
Overview
- 체감 난이도: ★★☆☆☆
- 문제 레벨: 실버 4
- 문제 유형: 자료구조, 정렬, 이분탐색, 해시를 사용한 집합과 맵
- 풀이 상태: 답안참고 / 스스로 해결
- 추후: 다시 풀어보기 / 간단 복습 / 완벽 이해
[문제]
https://www.acmicpc.net/problem/10816
[코드]
Counter 이용한 코드
from collections import Counter
N = int(input())
card = list(map(int, input().split()))
M = int(input())
chk = list(map(int, input().split()))
card_count = Counter(card)
result = [card_count[c] for c in chk]
print(' '.join(map(str, result)))
Dictionary 이용한 코드
N = int(input())
card = list(map(int, input().split()))
M = int(input())
chk = list(map(int, input().split()))
card_count = {}
for c in card:
if c in card_count:
card_count[c] += 1
else:
card_count[c] = 1
# 출력
result = [card_count.get(c, 0) for c in chk]
print(' '.join(map(str, result)))
반응형
'🚩 Coding Test > Baekjoon' 카테고리의 다른 글
[BOJ][Python] 1926 그림 (0) | 2024.08.20 |
---|---|
[BOJ][Python] 1966 프린터 큐 (0) | 2024.08.19 |
[BOJ][Python] 2504 괄호의 값 (0) | 2024.08.15 |
[BOJ][Python] 4949 균형잡힌 세상 (0) | 2024.08.09 |
[BOJ][Python] 9461 파도반 수열 (0) | 2024.07.31 |