题意:

有两个字符串,找一个最长子串是的该串既是第一个字的前缀,又是第二个串的后缀。

分析:

把两个串并起来然后在中间加一个无关字符,求next数组即可。

 #include <cstdio>
#include <cstring> const int maxn = + ;
char s1[maxn * ], s2[maxn];
int next[maxn * ], l; void get_next()
{
int k = -, j = ;
next[] = -;
while(j < l)
{
if(k == - || s1[k] == s1[j])
{
k++;
j++;
next[j] = k;
}
else k = next[k];
}
} int main(void)
{
//freopen("2594in.txt", "r", stdin);
while(scanf("%s%s", s1, s2) == )
{
l = strlen(s1);
int l2 = strlen(s2);
s1[l] = '#';
s1[l + ] = '\0';
strcat(s1, s2);
l = l + l2 + ;
get_next();
if(next[l] == )
{
puts("");
continue;
}
s1[next[l]] = '\0';
printf("%s %d\n", s1, next[l]);
} return ;
}

代码君

HDU 2594 (简单KMP) Simpsons’ Hidden Talents的更多相关文章

  1. hdu2597 Simpsons’ Hidden Talents

    地址:http://acm.hdu.edu.cn/showproblem.php?pid=2594 题目: Simpsons’ Hidden Talents Time Limit: 2000/1000 ...

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

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

  3. hdu 2594 Simpsons’ Hidden Talents KMP

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

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

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

  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. Discuz!NT3.6与网站整合(操作用户信息)解决方案

    因为网站要加个论坛,所以就用到了Discuz!NT3.6. 可惜目前官方论坛已经关闭,只有3.6版本的有源码,3.9的没有源码,不好操作,下载地址: http://download.comsenz.c ...

  2. Xcode Provisioning 路径

    ~/Library/MobileDevice/Provisioning Profiles

  3. 数字PID控制算法

    增量式PID控制算法 量式PID控制算法 2009-07-18 10:33 (转载 出处blog.ednchina.com/tengjingshu )blog.ednchina.com/tengjin ...

  4. 清除HTML中的特殊字符

    /// <summary>        /// 清楚HTML中的特殊字符        /// </summary>        /// <param name=&q ...

  5. 在windows下用FTP命令上传文件到Linux

    在桌面新建个文件夹,命名成MySQL.rpm.把需要上传的文件放到这个文件夹里.打开cmd窗口,开始用下面命令操作: C:\Users\huyadi>cd C:\Users\huyadi\Des ...

  6. 关于asp.net mvc4 在IE8下 导出excel失败的解决办法

    在使用FileResult向浏览器输出文件时(pdf,excel等),通常这样做: byte[] fileContents = Encoding.UTF8.GetBytes(sbHtml.ToStri ...

  7. uva 10205 模拟

    模拟题 题目描述挺长的.... #include <cstdio> #include <cstdlib> #include <cmath> #include < ...

  8. object-c 入门基础篇

    原地址:http://www.cnblogs.com/moonvan/archive/2011/10/13/2210498.html 一.Objective-C与C的渊源 Objective-C诞生于 ...

  9. netbean使用技巧

    1.让代码智能提示 有些情况下Ctrl+Space这个键被一些输入法占了,我们需要修改一下点击 工具->常规->快捷键映射->找到显示代码完成弹出式菜单->编辑为你喜欢的键就好 ...

  10. Oracle composite index column ordering

    Question:  I have a SQL with multiple columns in my where clause.  I know that Oracle can only choos ...