coding test - python/백준

백준 / 1296번 팀 이름 정하기 / Python 파이썬

sillon 2025. 4. 3. 00:04
728x90
반응형

*문제 출처는 백준에 있습니다.

문제 제목: 1296번 팀 이름 정하기

문제 사이트: https://www.acmicpc.net/problem/1296

 


나의 풀이

 

문제를 이해잘 해야함

 

from itertools import combinations
from collections import Counter
name = input()
n = int(input())
team_names = [input() for i in range(n)]
team_names.sort()
def probability(name,team_name):
    love_cnt = {'L':0,'O':0,'V':0,'E':0}
    name_count = Counter(name)
    team_name = Counter(team_name)
    for i in love_cnt:
        for j in team_name:
            if i == j:
                love_cnt[i] += team_name[j]
        for k in name_count:
            if i == k:
                love_cnt[i] += name_count[k]
    combination = combinations(love_cnt.keys(),2)
    result = [love_cnt[i[0]] + love_cnt[i[1]] for i in list(combination)] # [('L', 'O'), ('L', 'V'), ('L', 'E'), ('O', 'V'), ('O', 'E'), ('V', 'E')]
    return multiply(result) % 100
def multiply(arr):
    ans = 1
    for i in arr:
        ans *= i
    return ans
max_score = -1 # 나머지가 0일때도 있어서 -1 로 해서 비교
max_team = ''
for t in team_names:
    answer = probability(name,t)
    if answer > max_score:
        max_score = answer
        max_team = t
    elif answer == max_score and t < max_team: # 문자열끼리 비교하면 사전순으로 앞으로됨 
        max_team = t
print(max_team)

 

 


※ 알아야 할 것

- 문자열끼리 대소관계 비교하면 사전순으로 비교된다

- 나머지가 0일때도 대소관계 비교해야함

 

728x90
반응형