๐ 9375 | ํจ์ ์ ์ ํด๋น
https://www.acmicpc.net/problem/9375
๐ก Solution
- ์ท๋ค์ ์กฐํฉ์ ๊ตฌํ๋ ๋ฌธ์ ์ด๋ฏ๋ก ๋จผ์ ์์ ์ข ๋ฅ ๋ณ๋ก ์์์ ์๋ฅผ ์ผ๋ค. ์ด ๋ dictionary๋ฅผ ์ด์ฉํ์๋ค.
- (์์์ ์ + ์์ ๋ ๊ฒฝ์ฐ์ ์)๋ฅผ ์์์ ์ข ๋ฅ ๋ณ๋ก ๊ณฑํด์ฃผ๊ณ ์๋ชธ์ธ ๊ฒฝ์ฐ์ ์๋ฅผ ํ๋ ๋นผ์ค๋ค.
def countClothingCombinations(n) :
clothing = {}
result = 1
for i in range(n) :
clothing_name, clothing_type = input().split()
if clothing_type in clothing :
clothing[clothing_type] += 1
else :
clothing.update({clothing_type : 1})
for cloth, value in clothing.items() :
result *= (value+1)
return result - 1
t = int(input().rstrip())
while t :
n = int(input().rstrip())
print(countClothingCombinations(n))
t -= 1
๐ Note
• dict ์ํ
1. key์๋ง ์ ๊ทผ : for key in my_dict
2. value์๋ง ์ ๊ทผ : for value in my_dict.values()
3. ํค์ ๊ฐ ๋์์ ์ ๊ทผ : for key, value in my_dict.items()
'์๊ณ ๋ฆฌ์ฆ ๐ฉ๐ปโ๐ป > ๋ฐฑ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[BAEKJOON] 1946 | ์ ์ ์ฌ์ (0) | 2024.12.19 |
---|---|
[BAEKJOON] 14425 | ๋ฌธ์์ด ์งํฉ (0) | 2024.12.19 |
[BAEKJOON] 1431 | ์๋ฆฌ์ผ ๋ฒํธ (0) | 2024.12.18 |
[BAEKJOON] 19636 | ์์ ์๋ฎฌ๋ ์ด์ (0) | 2024.12.18 |
[BAEKJOON] 10820 | ๋ฌธ์์ด ๋ถ์ (0) | 2024.11.28 |