当前位置:网站首页>openjudge:找出全部子串位置
openjudge:找出全部子串位置
2022-07-28 05:18:00 【编程器系统】
描述
输入两个串s1,s2,找出s2在s1中所有出现的位置
两个子串的出现不能重叠。例如'aa'在 aaaa 里出现的位置只有0,2
输入
第一行是整数n
接下来有n行,每行两个不带空格的字符串s1,s2
输出
对每行,从小到大输出s2在s1中所有的出现位置。位置从0开始算
如果s2没出现过,输出 "no"
行末多输出空格没关系
样例输入
4 ababcdefgabdefab ab aaaaaaaaa a aaaaaaaaa aaa 112123323 a
样例输出
0 2 9 14 0 1 2 3 4 5 6 7 8 0 3 6 no
代码
n = int(input())
for i in range(n):
s = input().split()
m = 0
if s[1] not in s[0]:
print('no', end='')
for j in s[0]:
a = s[0].find(s[1],m)
if a == -1:
continue
else:
m = a + len(s[1])
print(a,'',end='')
print("") #每次循环换行边栏推荐
- Classes and objects [medium]
- New arrow function in ES6
- MySQL practice 45 lectures
- 低照度图像数据集
- 在ruoyi生成的对应数据库的代码 之后我该怎么做才能做出下边图片的样子
- latex和word之间相互转换
- There is no crossover in the time period within 24 hours
- 【单例模式】懒汉模式的线程安全问题
- Google browser cannot open localhost:3000. If you open localhost, you will jump to the test address
- restFul接口使用个人总结
猜你喜欢

SSLError

蒸馏模型图

Scope, execution process and life cycle of bean

First acquaintance with C language (1)

How to compare long and integer and why to report errors

The solution after the samesite by default cookies of Chrome browser 91 version are removed, and the solution that cross domain post requests in chrome cannot carry cookies

多线程进阶:synchronized底层原理,锁优化、锁升级的过程

mysql的日期与时间函数,varchar与date相互转换

科研论文写作方法:在方法部分添加分析和讨论说明自己的贡献和不同

Tomato timing dimming table lamp touch chip-dlt8t10s-jericho
随机推荐
Class class added in ES6
2021csdn blog star selection, mutual investment
2022 summer practice (PowerDesigner tutorial learning record) (first week)
Using RAC to realize the sending logic of verification code
JVM篇 笔记4:内存模型
C language characters and strings
JUC笔记
List<Long>,List<Integer>互相转换
mybaties foreach多选查询,index循环,取消and/or标签
关于swagger中的localDateTime
Offline loading of wkwebview and problems encountered
MySQL basic query
How about ink cloud?
图像增强——MSRCR
Localdatetime removes T, and jsonfield is invalid
论文写作用词
repackag failed: Unable to find main class
docker 部署 mysql5.7.35
mysql 为查询结果增加序号
多线程进阶:synchronized底层原理,锁优化、锁升级的过程