博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

随笔分类 -  KMP

摘要:求多字符串的最长公共子串(POW) 给定n个字符串,求这n个字符串的最长公共子串。例如给3个字符串:'abcb'、'bca'和'acbc',则这三个字符串的最长公共子串即为'bc'。输入第一行为n,下面n行即为这n个字符串。输出它们的最长公共子串。样例:输入:输出:3abcbbcaacbcbcView Code 1 #include<stdio.h> 2 #include<string.h> 3 4 char POW[200][200]; 5 char S[200]; 6 char T[200]; 7 in 阅读全文

posted @ 2012-10-11 21:35 皇星客栈--Linux 阅读(695) 评论(0) 推荐(0)

摘要:给定主串S和模式串T,求T串在S串中所有出现的位置,允许不同位置的T串有部分重叠。例如:S='abababab',T='abab',T在S中出现的总次数就是3次(包括1、3、5三个起点位置,虽然S[1..4]与S[3..6]有部分重叠,但这是允许的)。输入信息包括两行,第一行为S串,第二行为T串;按从小到大的顺序输出所有T串出现的位置。样例:输入:输出:abababababab1 3 5View Code 1 #include<stdio.h> 2 #include<string.h> 3 4 void get_nextval(char 阅读全文

posted @ 2012-10-07 00:31 皇星客栈--Linux 阅读(665) 评论(0) 推荐(0)

摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2087View Code 1 #include<stdio.h> 2 #include<string.h> 3 4 void get_nextval(char T[ ],int nextval[ ]) 5 {//求模式串T的next函数修正值并存入数组nextval. 6 int i=1,j=0; 7 int length; 8 nextval[1]=0; 9 length=strlen(T);10 11 while(i<length)12 ... 阅读全文

posted @ 2012-10-05 14:21 皇星客栈--Linux 阅读(222) 评论(0) 推荐(0)

摘要:View Code 1 #include<stdio.h> 2 #include<string.h> 3 4 void get_nextval(char T[ ],int nextval[ ]) 5 {//求模式串T的next函数修正值并存入数组nextval. 6 int i=1,j=0; 7 nextval[1]=0; 8 int length; 9 length=strlen(T);10 11 while(i<length)12 { 13 if(j==0||T[i]==T[j])14 ... 阅读全文

posted @ 2012-10-05 13:27 皇星客栈--Linux 阅读(379) 评论(0) 推荐(0)