当前位置:网站首页>Openjudge: maximum span of string
Openjudge: maximum span of string
2022-07-28 05:36:00 【Programmer system】
describe
There are three strings S,S1,S2, among ,S Length not exceeding 300,S1 and S2 Not more than 10. Want to test S1 and S2 Whether at the same time S It appears that , And S1 be located S2 Left side , And in S They don't cross each other ( namely ,S1 The right boundary point of is S2 On the left side of the boundary point ). Calculate the maximum span that meets the above conditions ( namely , Maximum separation distance : Far right S2 The starting point of is the same as the leftmost S1 The number of characters between the endpoints of ). If there is no one that meets the conditions S1,S2 There is , The output -1.
for example ,S = "abcd123ab888efghij45ef67kl", S1="ab", S2="ef", among ,S1 stay S In the 2 Time ,S2 Also in the S In the 2 Time , The maximum span is :18.
Input
Three strings :S, S1, S2, Separated by commas ( Be careful ,S, S1, S2 No commas or spaces in );
Output
S1 and S2 stay S Maximum span ; If in S There's nothing that satisfies the condition in S1 and S2, The output -1.
The sample input
abcd123ab888efghij45ef67kl,ab,ef
Sample output
18
Code
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')边栏推荐
- 图像增强评价指标学习之——结构相似性SSIM
- Learning of image enhancement evaluation index -- structural similarity SSIM
- First acquaintance with C language (2)
- mybaties foreach多选查询,index循环,取消and/or标签
- sql 查询list时两次的数据不一致,自动加上了limit
- 测试开发---自动化测试中的UI测试
- 多系统架构设计思考
- restFul接口使用个人总结
- When SQL queries the list, the data is inconsistent twice, and limit is automatically added
- 项目中问题合集
猜你喜欢

个人写的一个文件上传工具网站

Distillation model diagram
![[computer level 3 information security] overview of information security assurance](/img/f0/a72e61fda58ea93ca4e9db7274f6e3.png)
[computer level 3 information security] overview of information security assurance

latex和word之间相互转换

First acquaintance with C language (1)

Operation and use of collection framework

冶金物理化学复习 --- 气-液相反应动力学

Eccv2022 | 29 papers of Tencent Youtu were selected, including face security, image segmentation, target detection and other research directions

IDEA配置 service(Run Dashboard) 服务,多模块同时启动

Redis 之布隆过滤器
随机推荐
Feignclient calls the get method and reports an error resultvo{result= unknown exception. Exception details: request method 'post' not supported
注册中心服务eureka 切换到 nocas遇到的问题
C language: addition and deletion of linked list in structure
Advanced assignment method of ES6 -- Deconstruction assignment
测试开发---自动化测试中的UI测试
数据库面试
You must configure either the server or JDBC driver (via the ‘serverTimezone)
[singleton mode] thread safety of lazy mode
【MySQL】MySQL时区问题、数据库时间相差8小时问题解决
21 day SQL punch in summary
mybaties foreach多选查询,index循环,取消and/or标签
CentOS7安装MySQL5.7
Operation and use of collection framework
Digital twin technology creates visual application of smart mine
Oracle创建表、删除表、修改表(添加字段、修改字段、删除字段)语句总结
SSM project quick build project configuration file
多线程进阶:volatile的作用以及实现原理
IDEA配置 service(Run Dashboard) 服务,多模块同时启动
Non functional test
lamda 获取当前循环数,AtomicInteger