串的模式匹配算法实现
来源:互联网 发布:苹果系统检测软件 编辑:程序博客网 时间:2024/06/08 05:45
<span style="font-size:18px;">#include<stdio.h>#include<string.h>#define MAXSIZE 255#define PF printf("\n") int nextval[MAXSIZE+10];char T[MAXSIZE+1],S[MAXSIZE+1];//主串S,模式串Tvoid get_nextval(){int i=1,j=0;nextval[1]=0;while(i<strlen(T+1)){if(j==0||T[i]==T[j]){++i;++j;if(T[i]!=T[j])nextval[i]=j;elsenextval[i]=nextval[j]; } elsej=nextval[j];} } int KMP(){int i,j,lens=strlen(S+1),lent=strlen(T+1);for(i=1,j=0;i<=lens;++i){while(j>0&&S[i]!=T[j+1])j=nextval[j];if(S[i]==T[j+1])++j;if(j==lent)return 1; } return 0;} int main(){printf("请输入需要测试的次数:");int t;scanf("%d",&t);PF;while(t--){memset(S,'\0',sizeof(S));memset(T,'\0',sizeof(T)); printf("请输入主串:");PF;scanf("%s",S+1);printf("请输入模式串:");PF; scanf("%s",T+1); get_nextval();if(KMP())printf("OK╰( ̄▽ ̄)╭\n");elseprintf("NO╮(╯▽╰)╭\n");} return 0;} </span>
0 0
- 串的模式匹配算法实现
- 算法:KMP算法实现的模式匹配
- 【模式匹配】:关于模式匹配的算法实现2
- 数据结构之串的KMP模式匹配算法的实现
- 串的模式匹配(用一般算法实现)
- 串模式匹配算法的几种代码实现
- 串的模式匹配算法---Horspool及其实现
- 串的模式匹配算法
- 串的模式匹配算法
- 串的模式匹配算法
- 串的模式匹配算法
- 串的模式匹配算法
- 串的模式匹配算法
- 串的模式匹配算法
- 串的模式匹配算法
- 串的模式匹配算法
- 串的模式匹配算法
- 串的模式匹配算法
- ActiveMQ SSL应用之四 编写Java Demo类使用SSL连接ActiveMQ
- 信道与信道容量(一)
- CSS中line-height的学习
- python爬虫(下)--模拟登录与Captcha识别
- 窗口(单调队列)
- 串的模式匹配算法实现
- poj 2488 A Knight's Journey (dfs)
- 【文件】关于文件的复制函数
- C#异步编程之浅谈Task
- modelsim quick start
- sizeof运算符与求字符串长度函数strlen的区别
- WPF教程(十六)标签控件
- 类与对象的使用2
- mac-os use apt-get or yum