프로그래밍/Python
백준_python 9375번 패션왕 신해빈(딕셔너리)
O'bin
2024. 4. 26. 23:44
<문제 링크>
https://www.acmicpc.net/problem/9375
<정답 코드>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
t = int(input())
for _ in range(t):
n = int(input())
clothes = dict()
for _ in range(n):
name, type = map(str, input().split())
if type in clothes.keys():
clothes[type].append(name)
else:
clothes[type] = [name]
cnt = 1
for k in clothes:
cnt *= len(clothes[k]) + 1 # +1 으로 해당 의상 x 경우 추가
# cnt에서 -1 : 모든 의상 x 경우 제외
print(cnt - 1)
|
cs |
- 딕셔너리 사용이 자유로울 수 있도록 더 연습 필요
- 문제 풀이 시 작은 부분에 집중하지 말고, 전체 코드 흐름 단순하게 구성하는 방법 고민해보기