sunday 最快的字符串匹配
来源:互联网 发布:人工智能无人驾驶股票 编辑:程序博客网 时间:2024/05/16 19:43
#include<iostream>
#include<string>
using namespace std;
int sunday(const char *text, const char *find)
{
char map[CHAR_MAX];
int i;
int text_len = strlen(text);
int find_len = strlen(find);
if (text_len < find_len)
return -1;
//preprocess
for (i = 0; i<CHAR_MAX; i++)
map[i] = find_len + 1;
for (i = 0; i<find_len; i++)
map[find[i]] = find_len - i;
//match process
i = 0;
while (i <= (text_len - find_len))
{
if (strncmp(find, text + i, find_len) == 0)
return i;
else
i += map[text[i + find_len]];
}
return -1;
}
int main(){
char*value = "you are my pretty";
char *cmp = "ty";
cout << sunday(value,cmp);
}
#include<string>
using namespace std;
int sunday(const char *text, const char *find)
{
char map[CHAR_MAX];
int i;
int text_len = strlen(text);
int find_len = strlen(find);
if (text_len < find_len)
return -1;
//preprocess
for (i = 0; i<CHAR_MAX; i++)
map[i] = find_len + 1;
for (i = 0; i<find_len; i++)
map[find[i]] = find_len - i;
//match process
i = 0;
while (i <= (text_len - find_len))
{
if (strncmp(find, text + i, find_len) == 0)
return i;
else
i += map[text[i + find_len]];
}
return -1;
}
int main(){
char*value = "you are my pretty";
char *cmp = "ty";
cout << sunday(value,cmp);
}
阅读全文
0 0
- sunday 最快的字符串匹配
- 字符串的模式匹配:Sunday 算法
- 字符串匹配---Sunday算法
- 字符串匹配Sunday算法
- 字符串匹配-sunday算法
- Sunday字符串匹配
- 字符串匹配--Sunday算法
- 字符串匹配 sunday算法
- 字符串匹配sunday算法
- Sunday 字符串匹配算法
- Sunday字符串匹配算法
- 字符串匹配-Sunday算法
- sunday 字符串匹配算法的实现(支持二进制匹配)
- 字符串匹配新秀之Sunday
- 字符串单匹配SUNDAY算法
- 字符串模式匹配:Sunday算法
- 字符串匹配之sunday算法
- 字符串匹配Sunday算法实现
- 字体旋转+导航+媒体化查询
- 2017广东工业大学ACM新生杯初赛
- KeepVid Pro(网络视频下载工具)官方注册版V7.0.1.2下载 | keepvid pro 破解版
- 有n个人围成一圈,顺序排号。从第一个人开始报数(从1到3报数),凡报到3的人退出圈子,问最后留下的是原来第几号的那位。
- hibernate关系
- sunday 最快的字符串匹配
- 多总结和学习的几篇文章
- hibernate框架的核心配置文件=====hibernate.cfg.xml
- 微信支付SDK接入流程梳理
- 计算字符串中子串出现的次数
- js 对象转数组
- TensorFlow 实现多层 LSTM 的 MNIST 分类 + 可视化
- MongDB安装与连接
- 移植PTZ_continuous_move代码中遇到的soap->error 3