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

2022. 4. 8. 13:58알고리즘(Python)

name = input()
numOfTeam = int(input())
teamList = []
probList = []
teamIndex = 0
maxPorb = 0;
for i in range(numOfTeam):
    teamList.append(input())
    L = name.count("L") + str(teamList[i]).count("L")
    O = name.count("O") + str(teamList[i]).count("O")
    V = name.count("V") + str(teamList[i]).count("V")
    E = name.count("E") + str(teamList[i]).count("E")
    num = ((L+O) * (L+V) * (L+E) * (O+V) * (O+E) * (V+E)) % 100
    probList.append((num, teamList[i]))
    
probList.sort(key=lambda x : (-x[0], x[1]))

print(probList[0][1])
39200 kb 128 ms
from sys import stdin
a=stdin.readline().strip()
ini=0
r=[]
for i in range(int(stdin.readline().strip())):
    b=stdin.readline().strip()
    s=a+b
    l=s.count('L')
    o=s.count('O')
    v=s.count('V')
    e=s.count('E')
    chk=((l+o)*(l+v)*(l+e)*(o+v)*(o+e)*(v+e))%100
    if i==0:
        ini=chk
        r.append(b)
    else:
        if chk>ini:
            r[0]=b
            ini=max(chk,ini)
        elif chk==ini:
            r.append(b)
            r.sort()
            r.pop()
print(''.join(r))
30864 kb 68 ms
from sys import stdin

name = stdin.readline().rstrip()
numOfTeam = int(stdin.readline().rstrip())
probList = []
for i in range(numOfTeam):
    teamName = stdin.readline().rstrip()
    s = name+teamName
    L = s.count("L")
    O = s.count("O")
    V = s.count("V")
    E = s.count("E")
    num = ((L+O) * (L+V) * (L+E) * (O+V) * (O+E) * (V+E)) % 100
    probList.append((num, teamName))
    
probList.sort(key=lambda x : (-x[0], x[1]))

print(probList[0][1])
30864 kb 68 ms

 

'알고리즘(Python)' 카테고리의 다른 글

[틀린문제찾기] 미로찾기  (0) 2022.04.23