博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[kuangbin带你飞]专题十六 KMP & 扩展KMP & Manacher J - Simpsons’ Hidden Talents HDU - 2594(kmp前后缀)...
阅读量:4557 次
发布时间:2019-06-08

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

J - Simpsons’ Hidden Talents HDU - 2594

题目链接:

题目:

Homer: Marge, I just figured out a way to discover some of the talents we weren’t aware we had.
Marge: Yeah, what is it?
Homer: Take me for example. I want to find out if I have a talent in politics, OK?
Marge: OK.
Homer: So I take some politician’s name, say Clinton, and try to find the length of the longest prefix
in Clinton’s name that is a suffix in my name. That’s how close I am to being a politician like Clinton
Marge: Why on earth choose the longest prefix that is a suffix???
Homer: Well, our talents are deeply hidden within ourselves, Marge.
Marge: So how close are you?
Homer: 0!
Marge: I’m not surprised.
Homer: But you know, you must have some real math talent hidden deep in you.
Marge: How come?
Homer: Riemann and Marjorie gives 3!!!
Marge: Who the heck is Riemann?
Homer: Never mind.
Write a program that, when given strings s1 and s2, finds the longest prefix of s1 that is a suffix of s2.
InputInput consists of two lines. The first line contains s1 and the second line contains s2. You may assume all letters are in lowercase.OutputOutput consists of a single line that contains the longest string that is a prefix of s1 and a suffix of s2, followed by the length of that prefix. If the longest such string is the empty string, then the output should be 0.
The lengths of s1 and s2 will be at most 50000.Sample Input
clintonhomerriemannmarjorie
Sample Output
0rie 3 题意:给你两个字符串,求出第一个字符串的一个前缀,且这个前缀是第二个字符串的后缀,如果不存在,输出-1; 思路:可以再建立个字符串,把这两个字符串合并,中间用一个!来连接,防止相连前缀的情况,然后nextt[len]就是这个拼起来的字符串的相等的前后缀了,len就是这个拼的字符串的长度,
// // Created by HJYL on 2019/8/16.//#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;typedef long long ll;const int maxn=1e6+10;char str[maxn],str1[maxn],str2[maxn];int nextt[maxn];void getnext(){ int i=0,j=-1; nextt[0]=-1; int len=strlen(str2); while(i

 

转载于:https://www.cnblogs.com/Vampire6/p/11365307.html

你可能感兴趣的文章
[转]高颜值、好用、易扩展的微信小程序 UI 库,Powered by 有赞
查看>>
[转]SQL Server如何启用xp_cmdshell组件
查看>>
[转]微擎应用笔记3--manifest.xml文件使用说明
查看>>
Codeforces 1000C Covered Points Count 【前缀和优化】
查看>>
python高效读取文件、文件改写
查看>>
gulp
查看>>
pgsql查询优化之模糊查询
查看>>
不变模式
查看>>
matlab去云雾
查看>>
500lines项目简介
查看>>
Asp.net core logging 日志
查看>>
BOM浏览器对象模型
查看>>
Jq 遍历each()方法
查看>>
Android源码分析:Telephony部分–phone进程
查看>>
关于 redis.properties配置文件及rule
查看>>
WebService
查看>>
关于Java中重载的若干问题
查看>>
Java中start和run方法的区别
查看>>
23种设计模式中的命令模式
查看>>
[转载]年薪10w和年薪100w的人,差在哪里?
查看>>