#include<iostream>
#include<string>
using namespace std;
int SimpleIndex(const string &Target,const string &Old,int pos){
int i=pos,j=0;
while(i<Old.length()&&j<Target.length()){
if(Old[i]==Target[j]){
i++;
j++;
}else{
i=i-j+1;
j=0;
}
}
if(j>=Target.length()){
return i-j;
}else{
return -1;
}
}
int main(){
string t="abc";
string o="abdadc";
int answer=SimpleIndex(t,o,0);
printf("%d",answer);
return 0;
}
网友评论