728x90
반응형

import sys


M = int(sys.stdin.readline())
res = []
for k in range(M):
    N = int(sys.stdin.readline())
    B = {}
    for i in range(N):
        A = list(map(str, sys.stdin.readline().split()))

        if A[1] in B.keys():
            B[A[1]] += 1
        else:
            B[A[1]] = 1
    count = 1
    for key in B.keys():
        count *= B[key] +1
    res.append(count-1)
for i in res:
    print(i)

1. 딕셔너리 관련 식

 

B = {}  ==> B 딕셔너리 선언

A = list(map(str, sys.stdin.readline().split())) ==> A리스트에 데이터타입이 str로 저장

 

A =['sunglasses' , 'eyewear']

 

if A[1] in B.keys() : ==> B딕셔너리의 KEY 값에 A[1] 값이 있다면

     B[A[1]] += 1 ==> A[1]의 KEY값의 value 값에 1을 더한다.

else: ==> key값이 존재하지 않는다면

   B[A[1]] = 1 ==> 1로 초기화 한다.

 

 

EX ) 입력값 :

hat header

sung eye

tur header

 

B:{'header' : 2 , 'eye' : 1}

 

2. 조합구하기

count =1

 

for key in B.keys():

     count = count * (B[key] + 1) ==> 1* (2+1) * (1+1) = 6

 

count-1 ===> 겹치는거 제외해야하므로 -1을 처리한다.

 

 

 

 

728x90
반응형

+ Recent posts