#include<iostream>
using namespace std;
int main()
{
string s,s1,s2;
char c;
//找出s1,s2
while(cin>>c,c!=',') s+=c;
while(cin>>c,c!=',') s1+=c;
while(cin>>c) s2+=c;
if(s.size()<s1.size()||s.size()<s2.size()) puts("-1");
//确定s1最左边字符,s2最右边字符
else
{
int l=0;//起点
while(l+s1.size()<=s.size())
{
int k=0;
while(k<s1.size())
{
if(s[l+k]!=s1[k]) break;//判断s1是否在s中
k++;
}
if(k==s1.size()) break;//k的最大值为s.size()-1;
l++;
}
int r=s.size()-s2.size();
while(r>=0)
{
int k=0;
while(k<s2.size())
{
if(s[r+k]!=s2[k]) break;
k++;
}
if(k==s2.size()) break;
r--;
}
l+=s1.size()-1;
if(l>=r) puts("-1");//s1在s2右侧
else printf("%d\n",r-l-1);
}
return 0;
}
字符串最大跨距(778)
最新推荐文章于 2024-08-24 21:01:27 发布