当前位置:网站首页>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("") #每次循环换行边栏推荐
- 使用navicat或plsql导出csv格式,超过15位数字后面变成000(E+19)的问题
- lamda 获取当前循环数,AtomicInteger
- Class class added in ES6
- Bean的作用域、执行流程、生命周期
- Digital twin solutions inject new momentum into the construction of chemical parks
- BeanUtils. Copyproperties cannot copy different list sets problem solving lists.transform function
- regular expression
- Eccv2022 | 29 papers of Tencent Youtu were selected, including face security, image segmentation, target detection and other research directions
- 分享几种管理C程序中标志位的方法
- Non functional test
猜你喜欢

Invalid bound statement (not found): com.exam.mapper.UserMapper.findbyid

CentOS7安装MySQL5.7

使用navicat或plsql导出csv格式,超过15位数字后面变成000(E+19)的问题

PC side bug record

ByteBuffer. Position throws exception illegalargumentexception

Flask Development & get/post request

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

框架一步一步方便使用的流程

visio如何快速生成相同的图案,生成图像矩阵

自定义Json返回数据
随机推荐
凛冬已至,程序员该怎么取暖
解决Oracle使用in语句不能超过1000问题
You must configure either the server or JDBC driver (via the ‘serverTimezone)
yandex robots txt
JVM note 4: Memory Model
ECCV22 最新54篇论文主图整理
【计算机三级信息安全】信息安全保障概述
【idea插件神器】教你如何使用IDEA一键set实体类中所有属性
BigDecimal rounds and retains two decimal places
架构设计思考之一(SSO设计)
[computer level 3 information security] overview of information security assurance
深度学习医学图像模型复现
Thinking on multi system architecture design
mybaties foreach多选查询,index循环,取消and/or标签
论文写作用词
PC side bug record
图像增强评价指标学习之——结构相似性SSIM
[slam] lvi-sam analysis - Overview
What are the methods of array objects in Es5 and what are the new methods in ES6
MySQL basic query