题目来源:码蹄集
https://matiji.net/exam/brushquestion/489/778/B3FCFEC101BD05189BB74D522E019504
参考程序:
#include <iostream>
#include <string.h>
#define N 100000
int main() {
char s[N];
char zi[N];
gets(s);
gets(zi);
int len = strlen(zi);
int cnt = 0;
int i = 0;
while(s[i] != '\0' && cnt < len){
cnt = 0;
for ( ; cnt < len; ++cnt) {
if(s[cnt+i] != zi[cnt]){
break;
}
}
++i;
}
if(cnt == len){
std::cout << i-1 << std::endl;
}else{
std::cout << -1 << std::endl;
}
return 0;
}