博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 2594 Simpsons’ Hidden Talents(kmp)
阅读量:4137 次
发布时间:2019-05-25

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

Simpsons’ Hidden Talents

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5340 Accepted Submission(s): 1937
Problem Description
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.
Input
Input consists of two lines. The first line contains s1 and the second line contains s2. You may assume all letters are in lowercase.
Output
Output 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
Source
//题意:求一个字符串的前缀 和另一个字符串的后缀最多有多少相同的//所以不要控制模式串的长度,直接循环母串到结束,这样最后一次匹配的//就刚好是母串的后缀 #include 
#include
#include
#include
#include
#include
using namespace std;const int N=50000+10;char pat[N],text[N];int next_[N];int plen,tlen;inline void getNext(){ int j=0,k=-1; next_[0]=-1; while(j

转载地址:http://qbmvi.baihongyu.com/

你可能感兴趣的文章
我心目中的代码三要素
查看>>
Windows TortoiseSVN和Linux SVN入门
查看>>
你该怎样用svn才能避免冲突? (内附逻辑图和详细解释)
查看>>
什么是NAT?
查看>>
小小捣鼓一下手机和电脑---有助于理解NAT
查看>>
Linux挂载和Windows挂载的一个小区别
查看>>
C/C++的全局变量能否利用函数初始化?
查看>>
数据库入门
查看>>
html入门(要用到, 所以学学, 记录一下)
查看>>
html的<script>脚本:JavaScript入门
查看>>
html的<style>样式:css入门
查看>>
html测验小题目(来源于W3School)
查看>>
tri-networks integration?
查看>>
iptv与ott (转自维基百科)
查看>>
感受一下JS
查看>>
《一问一世界》 杨澜
查看>>
玩转Android中的setprop, getprop, watchprops命令
查看>>
switch中的非case非default语句会执行吗?
查看>>
三个bug的定位过程---也谈追踪配置库记录的重要性
查看>>
当同一个 HTML 元素被不止一个样式定义时,会使用哪个样式呢? (以后我要常驻www.w3school.com.cn)
查看>>