hduoj------2594 Simpsons’ Hidden Talents
Simpsons’ Hidden Talents
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2875 Accepted Submission(s): 1095
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.
The lengths of s1 and s2 will be at most 50000.
homer
riemann
marjorie
rie 3
简单的kmp。。。
代码:
#include<iostream>
#include<cstring>
#include<cstdlib>
using namespace std;
const int maxn=;
char str[maxn],st[maxn];
int next[maxn];
int main()
{
while(gets(str)!=NULL)
{
gets(st);
int lena=strlen(str);
int lenb=strlen(st);
int i=,j=-;
next[]=-;
while(i<lena)
{
if(j==-||str[i]==str[j])
next[++i]=++j;
else j=next[j];
}
i=j=;
while(i<lenb)
{
if(j==-||str[j]==st[i])
{
i++;
j++;
}
else j=next[j];
}
if(j==) printf("0\n");
else
printf("%s %d\n",st+lenb-j,j);;
} }
hduoj------2594 Simpsons’ Hidden Talents的更多相关文章
- HDU 2594 Simpsons’ Hidden Talents(辛普森一家的潜在天赋)
HDU 2594 Simpsons’ Hidden Talents(辛普森一家的潜在天赋) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 3 ...
- HDU 2594 Simpsons’ Hidden Talents(KMP的Next数组应用)
Simpsons’ Hidden Talents Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java ...
- hdu 2594 Simpsons’ Hidden Talents KMP
Simpsons’ Hidden Talents Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java ...
- hdu 2594 Simpsons’ Hidden Talents KMP应用
Simpsons’ Hidden Talents Problem Description Write a program that, when given strings s1 and s2, fin ...
- hdoj 2594 Simpsons’ Hidden Talents 【KMP】【求串的最长公共前缀后缀】
Simpsons' Hidden Talents Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java ...
- hdu 2594 Simpsons’ Hidden Talents(KMP入门)
Simpsons’ Hidden Talents Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java ...
- HDU——T 2594 Simpsons’ Hidden Talents
http://acm.hdu.edu.cn/showproblem.php?pid=2594 Time Limit: 2000/1000 MS (Java/Others) Memory Limi ...
- hdu 2594 Simpsons’ Hidden Talents(扩展kmp)
Problem Description Homer: Marge, I just figured out a way to discover some of the talents we weren’ ...
- 【HDU 2594 Simpsons' Hidden Talents】
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...
- hdu 2594 Simpsons’ Hidden Talents
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2594 思路:将两个串连起来求一遍Next数组就行长度为两者之和,遍历时注意长度应该小于两个串中的最小值 ...
随机推荐
- V-rep学习笔记:转动关节1
V-REP(Virtual Robot Experimentation Platform),是全球领先的机器人及模拟自动化软件平台.V-REP让使用者可以模拟整个机器人系统或其子系统(如感测器或机械结 ...
- 在CentOS下安装Redis
Redis比较傲娇,在windows上还没有很好的安装方式,不得已搞了个虚拟机玩玩. 装Redis十分简单,按照下面的几个命令来就行了. 安装命令 wget http://download.redis ...
- sql默认启动密码
首先启动sqlplus输入用户名:sqlplus / as sysdba密码空缺如果用户被锁定,记得加上SQL> alter user dbsnmp account unlock; User a ...
- [SAP ABAP开发技术总结]几个小技巧
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- HDU-4511 小明系列故事——女友的考验 floyd变种-标号递增最短路
题意:给定N个点,现在要求出从1号点到N号点的最短路.题目给的限制条件就是对于某条路径是不能够走的,但是可以选择某段路径走,另外就是所走的路径的标号必须是递增的. 分析:由于给定的是一些列的坐标点,这 ...
- iOS - OC 语言新特性
前言 相对于 Java,OC 语言是一门古老的语言了,而它又是一门不断发展完善的语言.一些新的编译特性,为 OC 语言带来了许多新的活力.在 Xcode7 中,iOS9 的 SDK 已经全面兼容了 O ...
- placeholder在不同浏览器下的表现及兼容方法(转)
1.什么是placeholder? placeholder是html5新增的一个属性,当input或者textarea设置了该属性后,该值的内容将作为灰字提示显示在文本框中,当文本框获得焦点(或 ...
- 手机CPU知识扫盲:谈谈手机CPU架构与原理 (全
CPU是手机上面最复杂,最贵的Soc(芯片),担任的也是手机中大脑的位 置,是手机跑分性能的决定性硬件.智能手机发展到今天,各大手机CPU厂商也从春秋战国逐渐到了现在四国鼎立的时代(高通,MTK,三星 ...
- AJAX的简介
AJAX 指异步JavaScript及XML(Asynchronous JavaScript And XML(异步JavaScript和XML)),是指一种创建交互式网页应用的网页开发技术. 国内通常 ...
- (一)mtg3000常见操作
一.查看MTG3000主控板IP地址: 重启设备后一直跑到shell,用户名和密码都输入admin,然后输入en进入命令行界面,输入sh int可查看设备IP等信息. 2.升级app.web程序