题目描述
字符串最大跨距
C++ 代码
#include <iostream>
#include <string>
using namespace std;
int main() {
string s, s1, s2;
getline(cin, s, ',');
getline(cin, s1, ',');
cin >> s2;
size_t l = s.find(s1);
size_t r = s.rfind(s2);
if (l == string::npos || r == string::npos) {
cout << "-1" << endl;
} else {
l += s1.length() - 1;
if (l >= r) {
cout << "-1" << endl;
} else {
cout << r - l - 1 << endl;
}
}
return 0;
}