알고리즘 문제풀이

백준 1296.팀이름 정하기 브론즈1 Python

아크몽 2024. 2. 9. 00:33
yeondu = input()
N = int(input())
arr = sorted([input() for _ in range(N)])
max_v,max_i = 0,0
for i in range(N):
    L = yeondu.count('L') + arr[i].count('L')
    O = yeondu.count('O') + arr[i].count('O')
    V = yeondu.count('V') + arr[i].count('V')
    E = yeondu.count('E') + arr[i].count('E')
    calc = ((L+O)*(L+V)*(L+E)*(O+V)*(O+E)*(V+E)) % 100
    if max_v < calc:
        max_v = calc
        max_i = i
print(arr[max_i])

 

 

예제는 다 통과한 코드, 메소드나 함수를 최소한으로 쓰고싶었다.

yeondu = input()
N = int(input())
result = 0
result_name = 'z'
for tc in range(N):
    name = input()
    L, O, V, E = 0, 0, 0, 0
    for i in name:
        if i == 'L':
            L += 1
        if i == 'O':
            O += 1
        if i == 'V':
            V += 1
        if i == 'E':
            E += 1
    for j in yeondu:
        if j == 'L':
            L += 1
        if j == 'O':
            O += 1
        if j == 'V':
            V += 1
        if j == 'E':
            E += 1
    calc = ((L + O) * (L+V) * (L + E) * (O + V) * (O + E) * (V + E)) % 100
    arr = [result_name,name]
    if result < calc:
        result = calc
        result_name = name
    elif result == calc:
        result = calc
        result_name = name
        arr.sort()

print(arr[0])