๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
์•Œ๊ณ ๋ฆฌ์ฆ˜ ๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป/๋ฐฑ์ค€

[BAEKJOON] 9375 | ํŒจ์…˜์™• ์‹ ํ•ด๋นˆ

by flowing1ife 2024. 12. 19.

๐Ÿ”Ž 9375 | ํŒจ์…˜์™• ์‹ ํ•ด๋นˆ

https://www.acmicpc.net/problem/9375


๐Ÿ’ก Solution

  1. ์˜ท๋“ค์˜ ์กฐํ•ฉ์„ ๊ตฌํ•˜๋Š” ๋ฌธ์ œ์ด๋ฏ€๋กœ ๋จผ์ € ์˜์ƒ ์ข…๋ฅ˜ ๋ณ„๋กœ ์˜์ƒ์˜ ์ˆ˜๋ฅผ ์„ผ๋‹ค. ์ด ๋•Œ dictionary๋ฅผ ์ด์šฉํ•˜์˜€๋‹ค.
  2. (์˜์ƒ์˜ ์ˆ˜ + ์•ˆ์ž…๋Š” ๊ฒฝ์šฐ์˜ ์ˆ˜)๋ฅผ ์˜์ƒ์˜ ์ข…๋ฅ˜ ๋ณ„๋กœ ๊ณฑํ•ด์ฃผ๊ณ  ์•Œ๋ชธ์ธ ๊ฒฝ์šฐ์˜ ์ˆ˜๋ฅผ ํ•˜๋‚˜ ๋นผ์ค€๋‹ค.

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()