字符串匹配 sunday算法

#include"iostream"
#include"string.h"
using namespace std;//BF算法
int strfind(char *s1,char *s2,int pos){int len1 = strlen(s1);int len2 = strlen(s2);int i = pos - 1,j = 0;while(j < len2){if(s1[i + j] == s2[j]){j++;}else{i++;j = 0;}}if(j == len2){return i + 1;}else{return 0;}
}//sunday算法
int strsun(char *s1,char *s2,int pos){int len1 = strlen(s1);int len2 = strlen(s2);int shift[256],i,j;//shift表的初始化for(i = 0;i < 256;i++){shift[i] = len2 + 1;} for(i = 0;i < len2;i++){shift[s2[i]] = len2 - i;}//遍历寻找i = pos - 1,j = 0;while(j < len2){if(s1[i + j] == s2[j]){j++;}else{i += shift[s1[i + len2]];    //不匹配就查表移动次数j = 0;}}if(j == len2){return i + 1;}else{return 0;}
}
int main(){char str1[] = "161234453218746321123456345567894";char str2[] = "123456";int n = 5;cout<<strfind(str1,str2,n)<<endl;cout<<strsun(str1,str2,n)<<endl;return 0;
}

 

转载于:https://www.cnblogs.com/oleolema/p/9048337.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/389620.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

5939. 半径为 k 的子数组平均值

5939. 半径为 k 的子数组平均值 给你一个下标从 0 开始的数组 nums &#xff0c;数组中有 n 个整数&#xff0c;另给你一个整数 k 。 半径为 k 的子数组平均值 是指&#xff1a;nums 中一个以下标 i 为 中心 且 半径 为 k 的子数组中所有元素的平均值&#xff0c;即下标在 i …

Adobe After Effects CS6 操作记录

安装 After Effects CS6 在Mac OS 10.12.5 上无法直接安装, 需要浏览到安装的执行文件后才能进行 https://helpx.adobe.com/creative-cloud/kb/install-creative-suite-mac-os-sierra.html , 但是即使安装成功, 也不能正常启动, 会报"You can’t use this version of the …

数据库逻辑删除的sql语句_通过数据库的眼睛查询sql的逻辑流程

数据库逻辑删除的sql语句Structured Query Language (SQL) is famously known as the romance language of data. Even thinking of extracting the single correct answer from terabytes of relational data seems a little overwhelming. So understanding the logical flow…

好用的模块

import requests# 1、发get请求urlhttp://api.xxx.xx/api/user/sxx_infodata{stu_name:xxx}reqrequests.get(url,paramsdata) #发get请求print(req.json()) #字典print(req.text) #string,json串# 返回的都是什么# 返回的类型是什么# 中文的好使吗# 2、发请求posturlhttp://api…

5940. 从数组中移除最大值和最小值

5940. 从数组中移除最大值和最小值 给你一个下标从 0 开始的数组 nums &#xff0c;数组由若干 互不相同 的整数组成。 nums 中有一个值最小的元素和一个值最大的元素。分别称为 最小值 和 最大值 。你的目标是从数组中移除这两个元素。 一次 删除 操作定义为从数组的 前面 …

BZOJ4127Abs——树链剖分+线段树

题目描述 给定一棵树,设计数据结构支持以下操作 1 u v d  表示将路径 (u,v) 加d 2 u v 表示询问路径 (u,v) 上点权绝对值的和 输入 第一行两个整数n和m&#xff0c;表示结点个数和操作数接下来一行n个整数a_i,表示点i的权值接下来n-1行,每行两个整数u,v表示存在一条(u,v)的…

数据挖掘流程_数据流挖掘

数据挖掘流程1-简介 (1- Introduction) The fact that the pace of technological change is at its peak, Silicon Valley is also introducing new challenges that need to be tackled via new and efficient ways. Continuous research is being carried out to improve th…

北门外的小吃街才是我的大学食堂

学校北门外的那些小吃摊&#xff0c;陪我度过了漫长的大学四年。 细数下来&#xff0c;我最怀念的是…… &#xff08;1&#xff09;烤鸡翅 吸引指数&#xff1a;★★★★★ 必杀技&#xff1a;酥流油 烤鸡翅有蜂蜜味、香辣味、孜然味……最爱店家独创的秘制鸡翅。鸡翅的外皮被…

786. 第 K 个最小的素数分数

786. 第 K 个最小的素数分数 给你一个按递增顺序排序的数组 arr 和一个整数 k 。数组 arr 由 1 和若干 素数 组成&#xff0c;且其中所有整数互不相同。 对于每对满足 0 < i < j < arr.length 的 i 和 j &#xff0c;可以得到分数 arr[i] / arr[j] 。 那么第 k 个…

[LeetCode]最长公共前缀(Longest Common Prefix)

题目描述 编写一个函数来查找字符串数组中的最长公共前缀。如果不存在公共前缀&#xff0c;返回空字符串 ""。 示例 1:输入: ["flower","flow","flight"]输出: "fl"示例 2:输入: ["dog","racecar",&quo…

域嵌套太深_pyspark如何修改嵌套结构域

域嵌套太深In our adventures trying to build a data lake, we are using dynamically generated spark cluster to ingest some data from MongoDB, our production database, to BigQuery. In order to do that, we use PySpark data frames and since mongo doesn’t have …

redis小结

Redis 切换到redis的目录 启动&#xff1a;./redis-server 关闭&#xff1a;killall redis-server Redis的数据类型&#xff1a; String字符 list链表 set集合&#xff08;无序&#xff09; Sort Set排序&#xff08;有序&#xff09; hash数据类型 string类型的数据操作 re…

WIN10下ADB工具包安装的教程和总结 --201809

ADB&#xff08;Android Debug Bridge&#xff09;是Android SDK中的一个工具, 使用ADB可以直接操作管理Android模拟器或者真实的Andriod设备。 ADB主要功能有: 在Android设备上运行Shell(命令行)管理模拟器或设备的端口映射在计算机和设备之间上传/下载文件将电脑上的本地APK软…

1816. 截断句子

1816. 截断句子 句子 是一个单词列表&#xff0c;列表中的单词之间用单个空格隔开&#xff0c;且不存在前导或尾随空格。每个单词仅由大小写英文字母组成&#xff08;不含标点符号&#xff09;。 例如&#xff0c;“Hello World”、“HELLO” 和 “hello world hello world”…

spark的流失计算模型_使用spark对sparkify的流失预测

spark的流失计算模型Churn prediction, namely predicting clients who might want to turn down the service, is one of the most common business applications of machine learning. It is especially important for those companies providing streaming services. In thi…

峰识别 峰面积计算 peak detection peak area 源代码 下载

原文:峰识别 峰面积计算 peak detection peak area 源代码 下载Comparative analysis of peak-detection techniques for comprehensive two-dimensional chromatography http://www.docin.com/p-172045359.html http://terpconnect.umd.edu/~toh/spectrum/ipeak.html R…

区块链开发公司谈区块链与大数据的关系

在过去的两千多年的时间长河中&#xff0c;数字一直指引着我们去探索很多未知的科学世界。到目前为止&#xff0c;随着网络和信息技术的发展&#xff0c;一切与人类活动相关的活动&#xff0c;都直接或者间接的连入了互联网之中&#xff0c;一个全新的数字化的世界展现在我们的…

Jupyter Notebook的15个技巧和窍门,可简化您的编码体验

Jupyter Notebook is a browser bases REPL (read eval print loop) built on IPython and other open-source libraries, it allows us to run interactive python code on the browser.Jupyter Notebook是基于IPL和其他开源库构建的基于REPL(读取评估打印循环)的浏览器&#…

给定有权无向图的邻接矩阵如下,求其最小生成树的总权重,代码。

#include<bits/stdc.h> using namespace std; #define INF 0x3f3f3f3f const int maxn 117; int m[maxn][maxn]; int vis[maxn], low[maxn]; /* 对于这道题目来将&#xff0c;m就是临接矩阵&#xff0c;vis是访问标记数组&#xff0c;low是最短距离数组 */ int n; int …

Ubuntu-16-04-编译-Caffe-SSD

该来的还是要来 之前为了偷懒想到使用 Docker 回避 Caffe SSD 编译的难题。结果&#xff0c;「天道好轮回&#xff0c;苍天饶过谁」。Docker 镜像内无法调用 GUI 显示以及摄像头&#xff0c;没法跑 ssd_pascal_webcam.py 做实时 Object Detection。所以没办法又得重新尝试编译 …