전공/백준
9375
yha97
2022. 10. 3. 20:27
날짜 : 2022. 10. 03
사용 언어 : python
문제
코드
import sys
t = int(sys.stdin.readline()) # 테스트케이스
for _ in range(t):
n = int(sys.stdin.readline()) # 옷 개수
clothes = dict()
for i in range(n):
name, cate = map(str, sys.stdin.readline().split()) # 옷 이름, 종류
if cate in clothes:
clothes[cate] += 1
else:
clothes[cate] = 1
t = 1
for i in clothes.values():
t *= (i + 1)
t -= 1
print(t)
알게된 점
- 옷 종류별 dictionary를 만들고 각 value + 1을 한 후에 전부 곱하고 마지막에 하나를 빼는 식으로 문제를 풀었다.
- value에 1을 더한 이유는 해당 종류의 옷을 입지 않은 케이스를 넣은 것이며 마지막에 1을 뺀 것은 전부 입지 않은 케이스가 중복되기 때문에 해당 케이스를 고려하여 차감했다.
참고 사이트
- https://hongcoding.tistory.com/60
[백준] 9375 패션왕 신해빈 (Python 파이썬)
www.acmicpc.net/problem/9375 9375번: 패션왕 신해빈 첫 번째 테스트 케이스는 headgear에 해당하는 의상이 hat, turban이며 eyewear에 해당하는 의상이 sunglasses이므로 (hat), (turban), (sunglasses), (hat,s..
hongcoding.tistory.com