지나가던 개발자

[Python] 백준 5637번(가장 긴 단어) 문제 풀이 본문

PS/Python

[Python] 백준 5637번(가장 긴 단어) 문제 풀이

KwonYongHyeon 2022. 11. 12. 18:06

 

from string import ascii_uppercase, ascii_lowercase

longest = ""
while True:
    s = input().split()
    if s == []:
        continue
    for i in range(len(s)):
        s[i] = list(s[i])
        for j in range(len(s[i])):
            if s[i][j] in list(ascii_uppercase) or s[i][j] in list(ascii_lowercase) or s[i][j] == "-":
                continue
            s[i][j] = ""
        s[i] = "".join(s[i])
            
    s.sort(key=len, reverse=True)
    
    if "E-N-D" in s:
        if s[0] == "E-N-D":
            if len(longest) < len(s[1]):
                longest = s[1]
        break
    
    if len(longest) < len(s[0]):
        longest = s[0]
        
print(longest.lower())
Comments