AcWing 778. 字符串最大跨距
原题链接
简单
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
string s,a,b;
char c;
while(cin>>c,c!=',')s=s+c;
while(cin>>c,c!=',')a=a+c;
while(cin>>c)b+=c;
int l=0;
while(l+a.size()<=s.size())
{
int k=0;
while(k<a.size())
{
if(a[k]!=s[l+k])break;
k++;
}
if(k==a.size())break;
l++;
}
int r=s.size()-b.size();
while(r>=0)
{
int i=0;
while(i<b.size())
{
if(b[i]!=s[r+i])break;
i++;
}
if(i==b.size())break;
r--;
}
l+=a.size()-1;
if(l>=r)puts("-1");
else cout<<r-l-1<<endl;
return 0;
}