输入一个字符串,将此字符串中最长的单词输出。要求至少使用一个自定义函数。
输入格式:
测试数据有多组,处理到文件尾。每组测试数据输入一个字符串(长度不超过80)。
输出格式:
对于每组测试,输出字符串中的最长单词,若有多个长度相等的最长单词,输出最早出现的那个。这里规定,单词只能由大小写英文字母构成。
输入样例:
Keywords insert, two way insertion sort,
Abstract This paper discusses three method for two way insertion
words. insert, two way sorted.
输出样例:
insertion
discusses
insert
while True:
try:
s=input()
for x in s:
if not x.isalpha():
s=s.replace(x,' ')
c=s.split()
max=''
for i in c:
if len(i)>len(max):
max=i
print(max)
except:
break