【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)动 ...
随机推荐
- 程序包com.sun.image.codec.jpeg不存在解决方法
https://blog.csdn.net/u011627980/article/details/50436842
- [Code Plus#4] 最短路
题目背景 在北纬 91° ,有一个神奇的国度,叫做企鹅国.这里的企鹅也有自己发达的文明,称为企鹅文明.因为企鹅只有黑白两种颜色,所以他们的数学也是以二进制为基础发展的. 比如早在 1110100111 ...
- Codeforces 451 E Devu and Flowers
Discription Devu wants to decorate his garden with flowers. He has purchased n boxes, where the i-th ...
- jquery ajax 跨域訪问样例
<script type="text/javascript"> $(function(){ $.ajax({ cache : false, type ...
- 转:linux下ip修改与域名解析查看等
转自: http://www.justwinit.cn/post/7038/ IP: ifconfiggateway:172.16.0.254 [root@localhost ~]# nets ...
- invlpg 指令简单介绍
invlpg 指令简单介绍 void tlb_invalidate(pde_t *pgdir, void *va) { // Flush the entry only if we're modifyi ...
- android-problem——remount of /system failed: Read-only file system
adb remount后仍旧不能对system进行读写.需要进行adb disable-verity 在Android6.0 (Android M)userdebug版本上(eng版本不存在该问题), ...
- Json实现异步请求(提交评论)
主要将代码粘贴,通过阅读代码理解当中的相关逻辑. html代码: <form id="form1" runat="server"> <p> ...
- FastDFS的配置、部署与API使用解读(2)以字节方式上传文件的客户端代码(转)
本文来自 诗商·柳惊鸿 Poechant CSDN博客,转载请注明源地址:FastDFS的配置.部署与API使用解读(2)上传文件到FastDFS分布式文件系统的客户端代码 在阅读本文之前,请您先通过 ...
- linux getopt函数详解
getopt(分析命令行参数) 表头文件 #include<unistd.h> 定义函数 int getopt(int argc,char * const argv[ ],const ...