当前位置:网站首页>openjudge:字符串最大跨距
openjudge:字符串最大跨距
2022-07-28 05:18:00 【编程器系统】
描述
有三个字符串S,S1,S2,其中,S长度不超过300,S1和S2的长度不超过10。想检测S1和S2是否同时在S中出现,且S1位于S2的左边,并在S中互不交叉(即,S1的右边界点在S2的左边界点的左侧)。计算满足上述条件的最大跨距(即,最大间隔距离:最右边的S2的起始点与最左边的S1的终止点之间的字符数目)。如果没有满足条件的S1,S2存在,则输出-1。
例如,S = "abcd123ab888efghij45ef67kl", S1="ab", S2="ef",其中,S1在S中出现了2次,S2也在S中出现了2次,最大跨距为:18。
输入
三个串:S, S1, S2,其间以逗号间隔(注意,S, S1, S2中均不含逗号和空格);
输出
S1和S2在S最大跨距;若在S中没有满足条件的S1和S2,则输出-1。
样例输入
abcd123ab888efghij45ef67kl,ab,ef
样例输出
18
代码
s = input().split(',')
a = s[0]
b = s[1]
c = s[2]
if b in a and c in a:
x = a.find(b)
y = a.rfind(c)
if x >= y:
print('-1')
else:
print(y-x-len(b))
else:
print('-1')边栏推荐
- Edge calculation kubeedge+edgemash
- repackag failed: Unable to find main class
- 21 day SQL punch in summary
- Antd setfieldsvalue warning problem cannot use 'setfieldsvalue' until you use 'getfielddecorator' or
- How to compare long and integer and why to report errors
- C language: realize the simple function of address book through structure
- PyTorch 使用 MaxPool 实现图像的膨胀和腐蚀
- JSON in JS (launch object deep copy)
- 类和对象【中】
- Mysql处理遗留数据样例
猜你喜欢

11.< tag-动态规划和子序列, 子数组>lt.115. 不同的子序列 + lt. 583. 两个字符串的删除操作 dbc

FusionGAN代码学习(一)

Distillation model diagram

在ruoyi生成的对应数据库的代码 之后我该怎么做才能做出下边图片的样子

VMware Workstation 与 Device/Credential Guard 不兼容。禁用 Device/Credential Guard

Digital twin technology creates visual application of smart mine

【idea插件神器】教你如何使用IDEA一键set实体类中所有属性

After ruoyi generates the code corresponding to the database, what should I do to make the following image look like

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

蒸馏模型图
随机推荐
多模块打包:程序包:xxx不存在
论文模型主图范例
ResNet结构对比
Performance test classification
Mabtis(一)框架的基本使用
Digital twin solutions inject new momentum into the construction of chemical parks
在ruoyi生成的对应数据库的代码 之后我该怎么做才能做出下边图片的样子
List<Long>,List<Integer>互相转换
C language: realize the simple function of address book through structure
Struct模块到底有多实用?一个知识点立马学习
JSON in JS (launch object deep copy)
图像增强——MSRCR
C language: some self realization of string functions
VMware Workstation 与 Device/Credential Guard 不兼容。禁用 Device/Credential Guard
Advanced assignment method of ES6 -- Deconstruction assignment
图像增强评价指标学习之——结构相似性SSIM
After ruoyi generates the code corresponding to the database, what should I do to make the following image look like
Thinking on multi system architecture design
yandex robots txt
7.<tag-字符串和API的取舍>补充: 剑指 Offer 05. 替换空格