AcWing 778. 字符串最大跨距
原题链接
困难
作者:
哈士奇最可爱
,
2021-02-14 12:40:25
,
所有人可见
,
阅读 349
#include <bits/stdc++.h>
using namespace std;
int main()
{
string s, s1, s2;
char c;
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");
else
{
int l;
for(l=0;l + s1.size() <= s.size();l++)
{
int k = 0;
while (k < s1.size())
{
if (s[l + k] != s1[k]) break;
k ++ ;
}
if (k == s1.size()) break;
}
int r;
for(r = s.size() - s2.size();r >= 0;r--)
{
int k = 0;
while (k < s2.size())
{
if (s[r + k] != s2[k]) break;
k ++ ;
}
if (k == s2.size()) break;
}
l += s1.size() - 1;
if (l >= r) puts("-1");
else printf("%d\n", r - l - 1);
}
return 0;
}