void main(){ char *S,*T; char s1[80] = "A STRING SEARCHING EXAMPLE CONSISTING OF SIMPLE TEXT"; char t1[80] = "STING"; char s2[80] = "00000000000000000000000000000000000000000000000000001";//前52个字符均为0 char t2[80] = "00000001"; int pos; //输出字符串 S="lixiang"; T="xi"; printf("Print the string S and T:\n"); printf("S=%s\nT=%s\n",S,T); //字符串定位 pos = 1; printf("\nFind the position of T in the S from pos %d is %d\n",pos,index_common(S,T,pos)); //字符串重新复制 printf("\nPrint the new string S and T:\n"); printf("Len=%d, S1=%s\nLen=%d, T1=%s\n",strlen(s1),s1,strlen(t1),t1); //字符串定位 printf("\nFind the position of T in the S from pos %d is %d\n",pos,index_common(S,T,pos)); //字符串重新复制 printf("\nPrint the new string S and T:\n"); printf("Len=%d, S=%s\nLen=%d, T=%s\n",strlen(s2),s2,strlen(t2),t2); //字符串定位 printf("\nFind the position of T in the S from pos %d is %d\n",pos,index_common(s2,t2,pos)); }
int main() { int n,n_common,n2; char s[20] = "adjfskjfskdjsfkglsi"; char t[5] = "skdj"; PSString ps, pt; //(1) create(s, ps); create(t, pt); //(2) n_common = index_common(ps, pt); int next[Maxsize],nextval[Maxsize]; printf("普通匹配情况下:\n"); print_result(n_common); //(3) get_next(pt, next); //(4) n = index_KMP(ps, pt, next); printf("\n\nKMP匹配情况下:\n"); print_result(n); for (int i = 0; i < 5; i++) printf("next[%d] = %d \n", i, next[i]); //(5) n2 = index_KMP2(ps, pt, nextval); printf("\n\nKMP修正版匹配情况下:\n"); print_result(n2); for (int i = 0; i < 5; i++) printf("nextval[%d] = %d \n", i, nextval[i]); return 0; }