AcWing 778. 字符串最大跨距
原题链接
困难
作者:
Woo
,
2021-05-05 10:22:49
,
所有人可见
,
阅读 187
代码
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
string s, s1, s2;
char a;
int m = 0;
while(cin >> a)
{
if(a != ',')
{
if(m == 0) s += a;
if(m == 1) s1 += a;
if(m == 2) s2 += a;
}
else if(a == ',') m ++;
}
int i, j, k;
i = s.find(s1);
j = s.rfind(s2);
if(s.find(s1) == string::npos || s.find(s2) == string::npos || i + s1.size() >= j) cout << -1;
else
{
k = j - i - s1.size();
cout << k;
}
return 0;
}