学进去-教育应平等而普惠
试题
类型:操作题
难度系数:0.40
所属科目:高中信息技术
同源词指由相同字母(不区分大小写)重排列形成的字符串,包括相同的字符串。当给定两个字符串s和p(s长度大于p长度),找到s中所有是p的同源词的子串,按出现的顺序输出这些子串的起始索引。如依次输入s=“cbaebAcdbabc”, p=“ABC”,则程序运行的结果如图所示。

(1)如果输入s的值不变,输入p为“ab”,则同源词的起点为______
(2)实现上述功能的部分Python程序如下,请在划线处填入合适的代码。

s=input('请输入s:')

p=input(请输入p:')

scount=[0]*26

pcount=[0]*26

m=len(s)

n=len(p)

ans=[]

def pos(c):

if ______:

return ord(c)-65

else:

return ord(c)-97

for i in range(n):

scount[pos(s[i])]+=1

pcount[pos(p[i])]+=1

if scount==pcount:

ans.append(0)

for i in range(m-n):

scount[pos(s[i])]-=1

scount[______]+=1

if scount==pcount:

ans.append______)

print('同源词起点为:', ans, end=" ")

编辑解析赚收入
收藏
|
有奖纠错

同类型试题

优质答疑

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
我要答疑
编写解析
解析:

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

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