题目描述
blablabla
样例
blablabla
C++ 代码
#include<cstdio>
#include<iostream>
#include<string.h>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
char sentence[1024];
scanf("%s",&sentence);
char *tokenPtr=strtok(sentence,",");//sentence必须是一个char数组,不能是定义成指针形式
string s[3];
for (int i = 0; i < 3; ++i) {
s[i]=tokenPtr;
tokenPtr= strtok(NULL,",");
}
int pos=0;
if((pos=s[0].find(s[1]))==string::npos){
cout<<-1<<endl;
return 0;
}
int pos1=0;
if((pos1=s[0].rfind(s[2]))==string::npos){
cout<<-1<<endl;
return 0;
}
// cout<<pos<<" "<<pos1<<endl;
if(pos1-pos<=0||pos1-pos<s[1].length())
{cout<<-1<<endl;
return 0;
}
cout<<pos1-pos-s[1].length()<<endl;
return 0;
}