AcWing 778. 字符串最大跨距
原题链接
困难
作者:
nangua
,
2019-08-09 11:59:00
,
所有人可见
,
阅读 876
#include <iostream>
using namespace std;
int main()
{
int i=0,j=0,k=0,l,r;
char a;
string s,s1,s2;
while(cin>>a)
{
if(a!=',')
{
if(i==0) s+=a;
else if(i==1) s1+=a;
else s2+=a;
}
else i++;
}
for(i=0;i<s.length();i++)
{
while(s[i+j]==s1[j]&&j<s1.length()) j++;
if(j==s1.length()) {l=i+j;break;}
j=0;
}
if(i==s.length()-1&&j!=s1.length()) {cout<<"-1";return 0;}
for(j=s.length()-1;j>=i+1;j--)
{
while(s[j+k]==s2[k]&&k<s2.length()) k++;
if(k==s2.length()) {r=j-1;break;}
k=0;
}
if(j==s.length()-1&&k!=s2.length()) {cout<<"-1";return 0;}
if(r<l) cout<<"-1";
else cout<<r-l+1;
return 0;
}