题目内容:
编写程序实现以下功能:输入两个字符串s1和s2,在字符串s1中检索指定字符串s2,获取所有匹配字符串的起始字符位置。
输入格式:
输入两个字符串,每行输入一个。
输出格式:
每行输出一个匹配字符串的起始字符位置。
输入样例:
cat dog cat dog cat dog cat cat
输出样例:
0 8 16 24
时间限制:500ms内存限制:32000kb
代码:
str1 = input()
str2 = input()
index = 0
while True:
index = str1.find(str2, index)
if index == -1:
break
print(index)
index = index + 1