编写一个程序,输入两个英文句子。每个英文句子的单词中间用空格隔开。输出两个句子最长的公共单词。

2024-12-02 20:58:15
推荐回答(1个)
回答1:

str1 = 'There is a tree behind the house.'[:-1].split()
str2 = 'A big tree is cut down there.'[:-1].split()
n = 0
togeter = []
for i in str1:
if i in str2:
togeter.append(i)
for max_word in togeter:
if len(max_word) < n:
n = len(max_word)
max_word= n
print max_word