#include<stdio.h>#include<string.h>intbrute_force_string_match( char *text, char *pattern){
int n = strlen(text);
int m = strlen(pattern);
for (int i = 0; i <= n - m; i++) {
int j;
for (j = 0; j < m; j++) {
if (text[i + j] != pattern[j]) {
break;
}
}
if (j == m) {
return i; // 匹配成功,返回匹配的起始位置
}
}
return-1; // 没有匹配成功
}
intmain(){
char *text = "ababcababcabcabc";
char *pattern = "abcabc";
int result = brute_force_string_match(text, pattern);
if (result != -1) {
printf("匹配的起始位置: %d\n", result);
} else {
printf("未找到匹配\n");
}
return0;
}