Sample Input

clinton
homer
riemann
marjorie

Sample Output

0
rie 3 看输出才题意。。。
拓展kmp特征很明显嘛。。。。
注意开始就匹配到尾的情况
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#define rap(i, a, n) for(int i=a; i<=n; i++)
#define rep(i, a, n) for(int i=a; i<n; i++)
#define lap(i, a, n) for(int i=n; i>=a; i--)
#define lep(i, a, n) for(int i=n; i>a; i--)
#define rd(a) scanf("%d", &a)
#define rlld(a) scanf("%lld", &a)
#define rc(a) scanf("%c", &a)
#define rs(a) scanf("%s", a)
#define MOD 2018
#define LL long long
#define ULL unsigned long long
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _ ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
const int maxn = , INF = 0x7fffffff;
int nex[maxn], ex[maxn]; void get_next(char *s)
{
int i=, j, po, len = strlen(s);
nex[] = len;
while(i+ < len && s[i] == s[i+])
i++;
nex[] = i;
po = ;
for(int i=; i<len; i++)
{
if(i+nex[i-po] < po + nex[po])
nex[i] = nex[i-po];
else
{
j = po + nex[po] - i;
if(j < ) j = ;
while(i + j < len && s[i+j] == s[j])
j++;
nex[i] = j;
po = i;
}
}
} int get_ex(char *s1, char *s2)
{
int i=, j, po, len1 = strlen(s1), len2 = strlen(s2);
get_next(s2);
while(s1[i] == s2[i] && i < len1 && i < len2)
i++;
ex[] = i;
if(i == len1)
return ;
po = ;
for(int i=; i<len1; i++)
{
if(i + nex[i - po] < po + ex[po])
ex[i] = nex[i-po];
else
{
j = po + ex[po] - i;
if(j < ) j = ;
while(i + j < len1 && j < len2 && s1[i+j] == s2[j])
j++;
ex[i] = j;
po = i;
if(ex[i] == len1 - i)
return i + ;
}
}
return ;
} char s1[maxn], s2[maxn];
int main()
{
while(~rs(s1))
{
rs(s2);
int flag = get_ex(s2, s1);
int len = strlen(s2);
if(flag)
{
rep(i, flag-, len)
cout<<s2[i];
cout<<" ";
cout<< ex[flag-] <<endl;
}
else
cout<< "" <<endl; } return ;
}

Simpsons’ Hidden Talents HDU - 2594(拓展kmp)的更多相关文章

  1. (KMP)Simpsons’ Hidden Talents -- hdu -- 2594

    http://acm.hdu.edu.cn/showproblem.php?pid=2594 Simpsons’ Hidden Talents Time Limit: 2000/1000 MS (Ja ...

  2. Simpsons’ Hidden Talents - HDU 2594(求相同的前缀后缀)

    题目大意:给你两个字符串,找出一个最大的子串,这个子串要是前面串的前缀并且是后面串的后缀...........   分析:next的简单运用吧,可以把两个串进行合并,中间加一个不能被匹配的字符,然后求 ...

  3. HDU 2594 Simpsons’ Hidden Talents(KMP的Next数组应用)

    Simpsons’ Hidden Talents Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java ...

  4. hdu 2594 Simpsons’ Hidden Talents KMP

    Simpsons’ Hidden Talents Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java ...

  5. hdu 2594 Simpsons’ Hidden Talents KMP应用

    Simpsons’ Hidden Talents Problem Description Write a program that, when given strings s1 and s2, fin ...

  6. hdu 2594 Simpsons’ Hidden Talents(KMP入门)

    Simpsons’ Hidden Talents Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java ...

  7. HDU 2594 Simpsons’ Hidden Talents(辛普森一家的潜在天赋)

    HDU 2594 Simpsons’ Hidden Talents(辛普森一家的潜在天赋) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 3 ...

  8. hdoj 2594 Simpsons’ Hidden Talents 【KMP】【求串的最长公共前缀后缀】

    Simpsons' Hidden Talents Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java ...

  9. hdu2594 Simpsons’ Hidden Talents kmp

    Simpsons’ Hidden Talents Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...

随机推荐

  1. DE1-SOC开发板使用学习

    1. Yocto build utility 工具是什么?Linux Console with framebuffer是什么? 2. 文档里面有几个Linux发布版本的,分别是ubuntu和LXDE版 ...

  2. Scala中==,eq与equals的区别

    根据官方API的定义: final def ==(arg0: Any): Boolean The expression x == that is equivalent to if (x eq null ...

  3. 一个很easy的脚本--php获取服务器端的相关信息

    存档: <html> <head> <meta http-equiv="content-type" content="text/html;c ...

  4. C# 多线程的等待所有线程结束的一个问题

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 3 ...

  5. React入门基础(学习笔记)

    这篇博客是我通过阅读React官方文档的教程总结的学习笔记,翻译可能存在误差,如有疑问请参见http://reactjs.cn/react/docs/tutorial.html . 一.所需文件 在编 ...

  6. python3 selenium实现自动登陆网页

    一.  安装python3与pycharm python安装参考链接:https://www.cnblogs.com/hepeilinnow/p/9727922.html pycharm最好安装专业版 ...

  7. TPO-18 C1 Apply for a part-time job on campus

    TPO-18 C1 Apply for a part-time job on campus 第 1 段 1.Listen to a conversation between a student and ...

  8. Dubbo使用心得2

  9. [笔记] FreeBSD使用小技巧

    非交互式添加用户 sed直接修改文件 sed -i '' 's/a/b/' file sed添加一行 sed '1a\ newline' file sed '1s/.*/&\'$'\nnewl ...

  10. 随机生成四则运算式2-NEW+PSP项目计划(补充没有真分数的情况)

    PS:这是昨天编写的随机生成四则运算式2的代码:http://www.cnblogs.com/wsqJohn/p/5264448.html 做了一些改进. 补:在上一次的运行中并没有加入真分数参与的运 ...