AcWing 778. 字符串最大跨距
原题链接
简单
作者:
SayYong
,
2024-10-15 16:15:07
,
所有人可见
,
阅读 1
#include <iostream>
using namespace std;
int main(void)
{
string s, s1, s2;
char c;
while (cin >> c, c != ',') s += c;
while (cin >> c, c != ',') s1 += c;
while (cin >> c) s2 += c;
int l = 0;
while (l + s1.size() < s.size()) {
if (s.substr(l, s1.size()) == s1) break;
l++;
}
int r = s.size() - 1;
while (r >= 0) {
if (s.substr(r, s2.size()) == s2) break;
r--;
}
if (l + s1.size() <= r) cout << r - l - s1.size() << endl;
else cout << -1 << endl;
// cout << s << endl;
// cout << s1 << endl;
// cout << s2 << endl;
return 0;
}