rfind()
反向查找
#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;
int t1=s.find(s1), t2 = s.rfind(s2); // rfind 反向查找
if(t1 !=-1 && t2 !=-1 && (t1 + s1.size() -1) < t2) cout<<t2-t1-s1.size()<<endl;
else cout<<-1<<endl;
}