学进去-教育应平等而普惠
试题
类型:操作题
难度系数:0.40
所属科目:高中信息技术
求字符环上的最长公共字符串:将字符串首尾相接后可以得到一个字符环,如图a和图b所示,分别为由字符串“sunlinght’s"和“sunshine’s"首尾相接后得到的环,它们的最长的公共字符串为“’ssun",长度为5。
图a              图b
   图c
编写python程序,实现如下功能:输入两个字符环,输出其最长公共子串和长度。程序运行界面如图c所示。Python程序如下,请在划线处填人合适的代码。
s1=input("请输入第一个字符环:")
s2=input("请输入第二个字符环:")
len1=len(s1)
len2=len(s2)
minlen=len1
if len2<len1:
            _____________________     
common=""
cl=0
for i in range(len1):
        for j in range(len2):
                    temp=0;itemp=i;jtemp=j
                    while s1[itemp]==s2[jtemp] and temp < minlen:
                                temp+=1
                                itemp=_____________________
                                jtemp=_____________________
                    if temp>cl:
                                cl=temp
                                if i<=itemp:
                                           common=s1[i:itemp]
                                else:
                                           common=_____________________
print("两字符环的最长公共子串为:"+common+";长度为:",cl)
编辑解析赚收入
收藏
|
有奖纠错

同类型试题

优质答疑

y = sin x, x∈R, y∈[–1,1],周期为2π,函数图像以 x = (π/2) + kπ 为对称轴
y = arcsin x, x∈[–1,1], y∈[–π/2,π/2]
sin x = 0 ←→ arcsin x = 0
sin x = 1/2 ←→ arcsin x = π/6
sin x = √2/2 ←→ arcsin x = π/4
sin x = 1 ←→ arcsin x = π/2

用户名称
2019-09-19

y = sin x, x∈R, y∈[–1,1],周期为2π,函数图像以 x = (π/2) + kπ 为对称轴
y = arcsin x, x∈[–1,1], y∈[–π/2,π/2]
sin x = 0 ←→ arcsin x = 0
sin x = 1/2 ←→ arcsin x = π/6
sin x = √2/2 ←→ arcsin x = π/4
sin x = 1 ←→ arcsin x = π/2

用户名称
2019-09-19
我要答疑
编写解析
解析:

奖学金将在审核通过后自动发放到帐

提交
我要答疑
我要答疑:
提交