【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)动 ...
随机推荐
- raspi集成库及安装
原文:http://blog.csdn.net/xukai871105/article/details/12684617 树莓派来自国外,国外嵌入式开源领域具有良好的分享精神,树莓派各种集成库也层 ...
- Codeforces Gym 100286J Javanese Cryptoanalysis 傻逼暴力
原题地址:http://codeforces.com/gym/100286/attachments/download/2013/20082009-acmicpc-northeastern-europe ...
- git log 查看版本演变历史
1.查看git操作历史 $ git log #git 查看git操作历史 $ git log --oneline #git 简洁的查看git变更记录 $ git log -n4 --onelin ...
- SolidEdge如何打开或关闭自动标注尺寸
工具-聪慧-自动标注尺寸
- 怎样去除JSP页面提示:Cannot return from outside a function or method.
今天用myeclipse10写JSP页面时出现: Cannot return from outside a function or method. onClick="return ch ...
- WheelView实现省市区三级联动(数据库实现版本号附带完整SQL及数据)
近期在实现收货地址功能,用到了省市区三级联动效果,网上找到一般都是xml或json.数据源陈旧改动麻烦.改动了一下使用数据库方式实现了一下 数据源解决.因为数据量比較大通过初始化批量运行SQL的方式不 ...
- Java学习之String StringBuffer StringBuilder区别
1.String:对象长度是不可变的,是线程安全. 2.StringBuffer:对象长度是可变的,是线程安全. 3.StringBuilder:对象长度是可变,不是线程安全.
- C#json数据的序列化和反序列化(将数据转换为对象或对象集合)
引用 System.Runtime.Serialization.Json
- 【转载】关于C#静态构造函数的几点说明
一.定义 静态构造函数是C#的一个新特性,其实好像很少用到.不过当我们想初始化一些静态变量的时候就需要用到它了.这个构造函数是属于类的,而不是属于哪里实例的,就是说这个构造函数只会被执行一次.也就是在 ...
- 释放SQL Server占用的内存 .Net 读取xml UrlReWriter 在web.config中简单的配置
释放SQL Server占用的内存 由于Sql Server对于系统内存的管理策略是有多少占多少,除非系统内存不够用了(大约到剩余内存为4M左右),Sql Server才会释放一点点内存.所以很多 ...