9375_패션왕 신해빈 (Python)
0. 출처
1. 기록
2. 풀이
(1) 아이디어, 시간복잡도, 자료구조
1. 아이디어
{
'headgear':['hat','turban'],
'eyewear':['sungalsses']
}
2. 시간복잡도
>>
3. 자료구조
>> 해시
(2) 예제 입력, 예제 출력
- 예제 입력 1 -
테스트 케이스 / 해빈이가 가진 의상의 수
2
3
hat headgear
sunglasses eyewear
turban headgear
3
mask face
sunglasses face
makeup face
- 예제 출력 1 -
5
3
(3) 코드
import sys
def input():
return sys.stdin.readline().rstrip()
t = int(input())
def OOTD(n):
temp = {}
for _ in range(n):
wear, type = input().split()
if type in temp:
temp[type].append(wear)
elif type not in temp:
temp[type] = [wear]
answer = 1
for key in temp:
answer *= (len(temp[key])+1)
print(answer-1)
for _ in range(t):
n = int(input())
OOTD(n)
(4) 정리
(5) 참고