博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SDUT-2772_数据结构实验之串一:KMP简单应用
阅读量:7052 次
发布时间:2019-06-28

本文共 733 字,大约阅读时间需要 2 分钟。

数据结构实验之串一:KMP简单应用

Time Limit: 1000 ms Memory Limit: 65536 KiB

Problem Description

给定两个字符串string1和string2,判断string2是否为string1的子串。

Input

输入包含多组数据,每组测试数据包含两行,第一行代表string1(长度小于1000000),第二行代表string2(长度小于1000000),string1和string2中保证不出现空格。

Output

对于每组输入数据,若string2是string1的子串,则输出string2在string1中的位置,若不是,输出-1。

Sample Input

abc

a
123456
45
abc
ddd

Sample Output

1

4
-1

Hint

Source

cjx

在做KMP的题目之前,推荐先去看一下这篇博客

  • (原创)详解KMP算法-孤~影()
    这里详细讲解了KMP的基础,有了基础再应付KMP的题目就简单多了。
#include 
#include
#include
int Next[1000050];char s1[1000050],s2[1000050];void get_next()//求next数组。{ int i,j,m; m = strlen(s2); i = 0; j = -1; Next[0] = -1; while(i

转载于:https://www.cnblogs.com/luoxiaoyi/p/9759009.html

你可能感兴趣的文章
【剑指offer】合并两有序单链表
查看>>
HDU 4360 As long as Binbin loves Sangsang spfa
查看>>
IT痴汉的工作现状24-Just for fun
查看>>
10个必需的iOS开发工具和资源
查看>>
如何专注
查看>>
IntelliJ IDEA常见问题解决办法汇总
查看>>
[LeetCode] Container With Most Water 装最多水的容器
查看>>
poj 3624 Charm Bracelet 背包DP
查看>>
用dedecms自定义表单创建简易自助预约系统
查看>>
读《了解你的学生》有感
查看>>
dedecms /member/flink_main.php SQL Injection Vul
查看>>
Dropbox Folder Sync – 让 Dropbox 同步任意文件夹
查看>>
PHP 网页爬虫
查看>>
用户队列服务API
查看>>
C# word开发
查看>>
spring mvc 与 jasper Report集成
查看>>
java学习笔记14--动态代理
查看>>
最简单的可取消多选效果(以从水果篮中挑选水果为例)【jsDEMO】
查看>>
worksteal thread pool
查看>>
视频数据采集模块设计
查看>>