欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

字符串最大跨距

程序员文章站 2022-03-08 14:03:51
...

字符串最大跨距

#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s,s1,s2;
	int i=0;
	char a;
	while(cin>>a)
		if(a!=',')
		{
			if(i==0)	s+=a;
			else if(i==1)	s1+=a;
			else	s2+=a;
		}
		else	i++;
	int t1,t2;
	t1=s.find(s1);	t2=s.rfind(s2);
	if(t1!=-1&&t2!=-1&&(t1+s1.length()-1)<t2)
		cout<<t2-t1-s1.length()<<endl;
	else	cout<<"-1"<<endl;
}
相关标签: 字符串