第5讲7*
#include <iostream>
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()) cout << "-1" << endl;
else
{
//s1的起点l
int l = 0; //从开始开始枚举
while(l + s1.size() <= s.size())
{
int k = 0;
while (k < s1.size())
{
if(s[l + k] != s1[k]) break;
k++;
}
if(k == s1.size()) break; //*验证是否相同
l++;
}
//s2的起点r
int r = s.size() - s2.size(); //从最后开始枚举
while(r >= 0)
{
int k = 0;
while (k < s2.size())
{
if(s[r + k] != s2[k]) break;
k++;
}
if(k == s2.size()) break;
r--;
}
//s1的末尾
l += s1.size() - 1;
//s2的开始 r
//s1 必须在 s2的左边
if(l >= r) cout << "-1" << endl;
else
{
cout << r - l -1 << endl;
}
}
return 0;
}