在一组单词中,查找出所有长度最长的单词,如果给定的一组单词是:"cad","VB","Python","MATLAB","hello","world"则输出结果为: the longest words are: Python MATLAB
时间: 2024-05-01 15:15:39 浏览: 53
要查找一组单词中的最长单词,可以遍历所有单词并记录最长的单词。以下是一个Python的实现:
```
words = ["cad", "VB", "Python", "MATLAB", "hello", "world"]
# 初始化最长单词为空字符串
longest_word = ""
# 遍历所有单词,如果当前单词比已知最长单词更长,则更新最长单词
for word in words:
if len(word) > len(longest_word):
longest_word = word
# 输出最长单词
print("The longest words are: ", end="")
for word in words:
if len(word) == len(longest_word):
print(word, end=" ")
print()
```
阅读全文