BNUOJ 6719 Simpsons’ Hidden Talents
Simpsons’ Hidden Talents
This problem will be judged on HDU. Original ID: 2594
64-bit integer IO format: %I64d Java class name: Main
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
Output
The lengths of s1 and s2 will be at most 50000.
Sample Input
clinton
homer
riemann
marjorie
Sample Output
0
rie 3
Source
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include <stack>
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;
char sa[<<],sb[];
int fail[<<];
void getFail(){
fail[] = fail[] = ;
for(int i = ; sa[i]; i++){
int j = fail[i];
while(j && sa[i] != sa[j]) j = fail[j];
fail[i+] = sa[i] == sa[j]?j+:;
}
}
int main() {
int i,j;
while(~scanf("%s %s",sa,sb)){
int len = strlen(sa),len2 = strlen(sb),i = len+len2;
for(i = len,j = ; sb[j]; i++,j++)
sa[i] = sb[j];
sa[i] = '\0';
getFail();
for(;fail[i] > len || fail[i] > len2; i--);
len = strlen(sa);
if(fail[i]){
printf("%s %d\n",sa+len-fail[i],fail[i]);
}else puts("");
}
return ;
}
BNUOJ 6719 Simpsons’ Hidden Talents的更多相关文章
- 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的Next数组应用)
Simpsons’ Hidden Talents Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java ...
- HDU 2594 Simpsons’ Hidden Talents(辛普森一家的潜在天赋)
HDU 2594 Simpsons’ Hidden Talents(辛普森一家的潜在天赋) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 3 ...
- hduoj------2594 Simpsons’ Hidden Talents
Simpsons’ Hidden Talents Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java ...
- hdu2594 Simpsons’ Hidden Talents kmp
Simpsons’ Hidden Talents Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- 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 ...
- hdu2594 Simpsons' Hidden Talents【next数组应用】
Simpsons’ Hidden Talents Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java ...
- HDU2594 Simpsons’ Hidden Talents 【KMP】
Simpsons' Hidden Talents Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java ...
随机推荐
- linux的SHELL编程
管道 | 特殊的重定向 前一个命令的输出作为后一个命令的输入; 管道连接的命令数没有限制; who|wc−l统计用户数ps |sort|more 按序显示当前进程名 字符:具有特定作用的特殊字符 ,& ...
- 随机L系统分形树 分类: 计算机图形学 2014-06-01 23:27 376人阅读 评论(0) 收藏
下面代码需要插入到MFC项目中运行,实现了计算机图形学中的L系统分形树. class Node { public: int x,y; double direction; Node(){} }; CSt ...
- C#中的list的System.Predicate<in T>和System.Comparison<in T>的应用
public class Data { ; ; ; ; public Data() { count++; ma = count; } } //一句话删除满足要求的集合 Asm.RemoveAll((D ...
- Oracle函数大全下载
Oracle函数大全下载 是一个压缩包,里面是一个chm格式的帮助文档,很实用.
- 解压上传的zip文件流和文件
/** * 解压上传的zip文件流 * @param stream * @param outputDirectory */ public static String unzip(InputStream ...
- sql中的日期时间处理
每个数据库,不同的日期格式化: 1.mysql 2.sqlserver 使用Convert()函数: select convert(char(10),GetDate(),120) as Date 第3 ...
- vue vueRouter vuex Axios webpack 前端常用内容
Axios 是一个基于 promise 的 HTTP 库,可以用在浏览器和 node.js 中.
- 解决webstorm中vue语法没有提示
首先看看webstrom内置的vue插件,打上勾,没有这个选项就要自己去下载插件了 如果插件还是没有语法提示,可以用下面的方法,自己添加语法进去搜索 unknown HTML tag attribut ...
- 面试之Redis
面:缓存中间件--Memcached和Redis的区别是什么? 答:Memcached的优点是简单易用,代码层次类似与Hash.支持简单数据类型,但不支持数据持久化存储,也不支持主从同步,也不支持分片 ...
- group by两个条件
学生表: 成绩表: 问题:统计各系各门课程的平均成绩 答案: select sdept,cno,AVG(grade)avg_grade from S join SC on S.sno = SC.sno ...