【题目链接】

点击打开链接

【算法】

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】 子串是否出现的更多相关文章

  1. LeetCode[5] 最长的回文子串

    题目描述 Given a string S, find the longest palindromic substring in S. You may assume that the maximum ...

  2. 最长回文子串-LeetCode 5 Longest Palindromic Substring

    题目描述 Given a string S, find the longest palindromic substring in S. You may assume that the maximum ...

  3. C语言计算字符串子串出现的次数

    #include<stdio.h>#include<string.h>int substring(char *str,char *str1);//函数原型int main(vo ...

  4. [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 ...

  5. [LeetCode] Minimum Window Substring 最小窗口子串

    Given a string S and a string T, find the minimum window in S which will contain all the characters ...

  6. [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 ...

  7. [LeetCode] Longest Substring Without Repeating Characters 最长无重复子串

    Given a string, find the length of the longest substring without repeating characters. For example, ...

  8. mysql判断一个字符串是否包含某子串

    使用locate(substr,str)函数,如果包含,返回>0的数,否则返回0 例子:判断site表中的url是否包含'http://'子串,如果不包含则拼接在url字符串开头 update ...

  9. 最长回文子串(Longest Palindromic Substring)

    这算是一道经典的题目了,最长回文子串问题是在一个字符串中求得满足回文子串条件的最长的那一个.常见的解题方法有三种: (1)暴力枚举法,以每个元素为中心同时向左和向右出发,复杂度O(n^2): (2)动 ...

随机推荐

  1. T1079 回家 codevs

    http://codevs.cn/problem/1079/ 时间限制: 1 s  空间限制: 128000 KB  题目等级 : 白银 Silver~死坑 题目描述 Description 现在是晚 ...

  2. 一点点VIM

    VIM 当你喜欢它时,你会发现真的不错,不过配置真是麻烦, 不过万事开头难,当你熟练时真的会发现她的美. syntax on set nu colo evening set mouse=a set c ...

  3. Java中ArrayList类

    ArratList 类:存放同一数据类型容器(只能为引用数据类型,因实际其内部存放的是地址) 1.导入其所在包 import java.util.ArratList 2.创建对象 ArrayList& ...

  4. JQuery select 编程时选中原有的值

    js 此为核心代码 $(document).ready(function(){ $("#carTypeId").attr("value",'${carInfo. ...

  5. java学习笔记总略

    二.正文(一)Java1.接口和抽象类的区别①抽象类里可以有构造方法,而接口内不能有构造方法.②抽象类中可以有普通成员变量,而接口中不能有普通成员变量.③抽象类中可以包含非抽象的普通方法,而接口中所有 ...

  6. Linux Shell高级技巧

    Linux Shell高级技巧(一) http://www.cnblogs.com/stephen-liu74/archive/2011/12/22/2271167.html一.将输入信息转换为大写字 ...

  7. 64-bit Itanium与x64

    64-bit Itanium是什么意思 64-bit Itanium,指的是intel 安腾处理器,intel安腾处理器是Intel的某一代处理器,当然是在酷睿(即core)这一代之前出来的. ora ...

  8. ZT:CSS实现水平|垂直居中漫谈

    有篇博客园网友‘云轩奕鹤’的文章不错,转载在这里以供需要时查阅. http://www.cnblogs.com/jadeboy/p/5107471.html

  9. 一根数据线玩转树莓派Zero

    0. 前言 原创文章,转载引用务必注明链接.水平有限,如有疏漏,欢迎指正. 本文使用Markdown写成,为获得更好的阅读体验和正常的链接.图片显示,请访问我的博客原文: http://www.cnb ...

  10. BeagleBone Black Industrial 进阶设置(性能优化以及延长板载eMMC存储寿命)

    前言 原创文章,转载引用务必注明链接.水平有限,欢迎指正. 本文使用markdown写成,为获得更好的阅读体验,推荐访问我的博客原文: http://www.omoikane.cn/2016/09/1 ...