백준 5637번: 가장 긴 단어 #Python

ColorlessDia·2024년 2월 26일

algorithm/baekjoon

목록 보기
97/809
import sys

max_length = 0
max_length_word = ''

while True:
    line = sys.stdin.readline().rstrip().split()

    for word in line:
        word_length = 0
        formatted_word = ''
        
        for char in word:
            if char.isalpha() or char == '-':
                word_length += 1
                formatted_word += char
        
        if max_length < word_length:
            max_length = word_length
            max_length_word = formatted_word

    if 'E-N-D' in line:
        break

print(max_length_word.lower())

0개의 댓글