当前位置:网站首页>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("") #每次循环换行边栏推荐
猜你喜欢

BigDecimal rounds and retains two decimal places
![[slam] lvi-sam analysis - Overview](/img/66/f15f6f574807b9a783e9321c71d422.png)
[slam] lvi-sam analysis - Overview

BigDecimal 进行四舍五入 四舍六入和保留两位小数

CentOS7安装MySQL5.7

First acquaintance with C language (2)

How practical is the struct module? Learn a knowledge point immediately

ByteBuffer. Position throws exception illegalargumentexception

restFul接口使用个人总结

论文写作用词

Scope, execution process and life cycle of bean
随机推荐
Mysql数据库索引(innodb引擎)
Database date types are all 0
正则表达式
ES6 new variable modifiers let and const, new basic data type symbol
New arrow function in ES6
多线程进阶:volatile的作用以及实现原理
latex使用\hl进行高亮时遇到引用总是报错,显示少了括号或者多了括号
Video twins: the starting point of informatization upgrading of smart Parks
Autoreleasepool problem summary
Eccv2022 | 29 papers of Tencent Youtu were selected, including face security, image segmentation, target detection and other research directions
[slam] lvi-sam analysis - Overview
ByteBuffer.position 抛出异常 IllegalArgumentException
【MySQL】MySQL时区问题、数据库时间相差8小时问题解决
(黑马)MYSQL初级-高级笔记(博主懒狗)
MySQL date and time function, varchar and date are mutually converted
MySQL uses list as a parameter to query
repackag failed: Unable to find main class
C language: realize the simple function of address book through structure
Problems encountered when the registry service Eureka switches to nocas
Non functional test