题解 | #牛群的信息传递#
牛群的信息传递
https://www.nowcoder.com/practice/0130cb88968a441b9eedbc103466d2bf
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param message string字符串
* @param keyword string字符串
* @return int整型
*/
#include <string.h>
#include <time.h>
int findKeyword(char* message, char* keyword ) {
// write code here
int cnt=0;
int A=strlen(keyword);
int B=strlen(message);
int i=0,j=0;
for(i=0;i<B;i++)
{
while(j<A && message[i]==keyword[j])
{
cnt=i;
j++;
}
}
return j==A?cnt-A+1:-1;
}