【CAIOJ1177】 子串是否出现
【题目链接】
【算法】
KMP
【代码】
#include<bits/stdc++.h>
using namespace std;
#define MAXA 1000010
#define MAXB 1010 int i,j,lenA,lenB;
int p[MAXB];
char SA[MAXA],SB[MAXB]; int main() { scanf("%s",SA+); lenA = strlen(SA+);
scanf("%s",SB+); lenB = strlen(SB+);
p[] = ;
for (i = ; i <= lenB; i++) {
j = p[i-];
while ((j > ) && (SB[i] != SB[j+])) j = p[j];
if (SB[i] == SB[j+]) p[i] = j + ;
else p[i] = ;
} j = ; for (i = ; i <= lenA; i++) {
while ((j > ) && (SA[i] != SB[j+])) j = p[j];
if (SA[i] == SB[j+]) j++;
if (j == lenB) {
cout<< i - lenB + << ' ' << i << endl;
exit();
}
} cout<< "NO" << endl; return ; }
【CAIOJ1177】 子串是否出现的更多相关文章
- LeetCode[5] 最长的回文子串
题目描述 Given a string S, find the longest palindromic substring in S. You may assume that the maximum ...
- 最长回文子串-LeetCode 5 Longest Palindromic Substring
题目描述 Given a string S, find the longest palindromic substring in S. You may assume that the maximum ...
- C语言计算字符串子串出现的次数
#include<stdio.h>#include<string.h>int substring(char *str,char *str1);//函数原型int main(vo ...
- [LeetCode] Longest Substring with At Most Two Distinct Characters 最多有两个不同字符的最长子串
Given a string S, find the length of the longest substring T that contains at most two distinct char ...
- [LeetCode] Minimum Window Substring 最小窗口子串
Given a string S and a string T, find the minimum window in S which will contain all the characters ...
- [LeetCode] Substring with Concatenation of All Words 串联所有单词的子串
You are given a string, s, and a list of words, words, that are all of the same length. Find all sta ...
- [LeetCode] Longest Substring Without Repeating Characters 最长无重复子串
Given a string, find the length of the longest substring without repeating characters. For example, ...
- mysql判断一个字符串是否包含某子串
使用locate(substr,str)函数,如果包含,返回>0的数,否则返回0 例子:判断site表中的url是否包含'http://'子串,如果不包含则拼接在url字符串开头 update ...
- 最长回文子串(Longest Palindromic Substring)
这算是一道经典的题目了,最长回文子串问题是在一个字符串中求得满足回文子串条件的最长的那一个.常见的解题方法有三种: (1)暴力枚举法,以每个元素为中心同时向左和向右出发,复杂度O(n^2): (2)动 ...
随机推荐
- Unity3D 对象池思想 在游戏开发中的运用
分类:U3D 1.在王者荣耀中,每30秒小兵会出现一波,出现之后会被敌方玩家或敌方小兵销毁,一局游戏下来,小兵会被创建多次,同时也会被销毁,在游戏中,这种频繁的创建和销毁游戏对象是很损耗性能的.在游戏 ...
- 你还在为移动端选择器picker插件而捉急吗?
http://www.cnblogs.com/jingh/p/6381079.html 开题:得益于项目的上线,现在终于有时间来写一点点的东西,虽然很浅显,但是我感觉每经历一次项目,我就学到了很多的东 ...
- 优秀的数据序列和还原类----TSimpleMsgPack
优秀的数据序列和还原类----TSimpleMsgPack TSimpleMsgPack是D10天地弦的作品. 优点:至简,就一个单元文件实现,不需要引用其他单元. 缺点:不是标准的MSGPACK实现 ...
- Tar压缩文件
[root@test /root]# tar [-zxcvfpP] filename [root@test /root]# tar -N 'yyyy/mm/dd' /path -zcvf targ ...
- Linux索引节点(Inode:no space for device)用满导致的一次故障
问题描写叙述 在storm測试环境集群上上nimbus和supervisor自己主动挂调.重新启动时显示no space for device,也不能创建,加入文件及文件夹,df -h查看 ilesy ...
- 【J2EE】十三个规范:愿天下苍生,人人如猿。
学习了J2ee后对java这个立足标准化的行为感到深深的佩服. 收买什么都不如收买人心,培养啥子都不如培养 习惯.没错,java就是在培养行业习惯,以一纸规范屹立不倒.毕竟技术什么的层出不穷,再新再前 ...
- SolidEdge 工程图中如何控制是否显示爆炸图组装线
右击视图,点击性质,取消勾选"显示流线" 即可取消爆炸视图的装配线
- 有关不同浏览器不同版本号的css以及js计算高度的问题
1.input在全部浏览器以及全部的版本号中,都是定义了高度.然后再定义padding或者border值.这时候都会撑开.高度是本身的高度在padding值和border值 2.select在gool ...
- evaluate-reverse-polish-notation——栈
Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are+,-,*, ...
- 进程监控模块配置与使用 ------ACE(开源项目)
下面我先从此工程的作用讲起: 此工程适用于程序异常退出,然后自动重启该程序.对于,系统重启不了该进程,那此程序将返回-1,也无法进行下一步工作. 下面,先从配置开始讲起: 参考资料:http://hi ...