[백준] 1296. 팀 이름 정하기

원숭2·2022년 2월 3일
0

백준

목록 보기
24/54

문제

풀이

  1. count함수와 2중 for문을 이용하여 문제의 조건대로 구현함.
  2. 크기 비교와 사전 순 비교를 동시에 하기 위해 tuple과 sort함수를 이용함.

코드

import sys

def solution() :
    y = sys.stdin.readline().rstrip()
    n = int(sys.stdin.readline())
    std = list('LOVE')
    
    if n == 1 :
        print(sys.stdin.readline().rstrip())
    else :
        res = []
        for _ in range(n) :
            s = sys.stdin.readline().rstrip()
                
            calc = 1
            for i in range(len(std)) :
                for j in range(i+1, len(std)) :
                    calc *= (y.count(std[i]) + s.count(std[i])) + (y.count(std[j]) + s.count(std[j]))
            
            res.append((calc % 100, s))
        
        res.sort(key = lambda x : (-x[0], x[1]))

        print(res[0][1])
                                 
solution()

0개의 댓글