HDU-2594 Simpsons’ Hidden Talents

题目链接:HDU-2594

题目大意:给定两个字符串 问第一个字符串前缀与第二个字符串的后缀的最大的重复部分有多长 不为0的话将他们输出

解题思路:花里胡哨的过不去 直接将两个字符串拼接进行kmp的findNext就好,注意两个字符串要找到最短的长度,然后1截取前最短,2截取后最短,然后findNext,注意如果结果比两个字符串的最小长度大的话,结果就是最小长度,不然aaa aa这种情况会出错

代码块:

#include<iostream>
#include<string>
#include<cstring>
#include<cstdio>using namespace std;string strA, strB;
int minX = 0;
int nex[100005];int findNex() {int lenA = strA.length();int lenB = strB.length();minX = lenA < lenB ? lenA : lenB;string strC = "";strC += strA.substr(0, minX);strC += strB.substr(lenB - minX, lenB);int i = 1, j = 0;while(i < strC.length()){if(strC[i] == strC[j]){nex[i++] = ++j;}else if(j != 0){j = nex[j - 1];}else{nex[i++] = 0;}}return nex[strC.length() - 1];
}int main() {while(cin>>strA>>strB) {int res = findNex();if(res){if(res > minX) res = minX;for(int i = 0; i < res; i++){cout<<strA[i];}cout<<" ";}cout<<res<<endl;memset(nex, 0, sizeof(nex));}return 0;
}

HDU-2594 Simpsons’ Hidden Talents相关推荐

  1. HDU 2594 Simpsons’ Hidden Talents (字符串-KMP)

    Simpsons' Hidden Talents Problem Description Homer: Marge, I just figured out a way to discover some ...

  2. HDU 2594 - Simpsons’ Hidden Talents(KMP)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2594 题目描述: 给定两个字符串s1,s2,问是否存在一个最长的子串,使得这个子串既是s1的前缀又是 ...

  3. HDU - 2594 Simpsons’ Hidden Talents(KMP的next数组)

    题目链接:点击查看 题目大意:给出两个字符串s1和s2,求出s1的前缀和s2的后缀可以匹配的最大长度,并输出其匹配的子字符串 题目分析:因为涉及到了前后缀的关系,我想的是可以将s1和s2连接成一个字符 ...

  4. HDUOJ 2594 Simpsons’ Hidden Talents

    题目链接 Problem Description Homer: Marge, I just figured out a way to discover some of the talents we w ...

  5. Simpsons’ Hidden Talents(辛普森一家的隐藏天赋 )(kmp经典模板题) HDU - 2594

    题目:Simpsons' Hidden Talents(辛普森一家的隐藏天赋 ) 中文大意 Homer: Marge, I just figured out a way to discover som ...

  6. kmp总结(相关例题1. Simpsons’ Hidden Talents 2.Oulipo)

    kmp相关及相关例题 文章目录 kmp相关及相关例题 一.kmp算法最常规使用方法 二.相关例题 1. Simpsons' Hidden Talents 2.Oulipo 一.kmp算法最常规使用方法 ...

  7. HDU2594(Simpsons’ Hidden Talents)

    Simpsons' Hidden Talents Problem Description Homer: Marge, I just figured out a way to discover some ...

  8. B - Simpsons’ Hidden Talents

    B - Simpsons' Hidden Talents Homer: Marge, I just figured out a way to discover some of the talents ...

  9. Simpsons’ Hidden Talents (HDU-2594)

    Simpsons' Hidden Talents (HDU-2594) Homer: Marge, I just figured out a way to discover some of the t ...

最新文章

  1. C++程序的内存布局
  2. python mysql库对比_mysqlclient和PyMySQL对比
  3. Java:封装的概念,UML类图,构造方法,this关键字,static关键字,方法重载,包package
  4. 设计模式-观察者模式(Observer)
  5. 软件设计原则(三)里氏替换原则 -Liskov Substitution Principle
  6. Crontab命令--Linux
  7. 安卓百度地图附近poi搜索以及到指定poi的换乘方案
  8. 手动通过tomcat加载一个war项目。
  9. js取字符串后四位_JS逆向 | 某验滑块加密参数逆向分析
  10. java 集合类 *****
  11. 从零开始学电脑办公_每天学一点 7天学会使用电脑办公操作
  12. mysql二进制日志特点_MySQL二进制日志分析-概述篇
  13. 基于JAVA+SpringBoot+Vue+Mybatis+MYSQL的小程序医院预约挂号系统
  14. Win10系列:C#应用控件进阶3
  15. protocol buffer与json对比
  16. (dfs)[USACO3.4]“破锣摇滚”乐队 Raucous Rockers
  17. WPS页眉页脚怎么设置每页不同
  18. 耿建超英语语法---陈述句(2)
  19. 【Visual C++】游戏开发笔记四十三 浅墨DirectX教程十一 为三维世界添彩:纹理映射技术(二)
  20. 昨天看《天使爱美丽》

热门文章

  1. subsequent settlement in SD
  2. java 一年工作经验简历_java一年工作经验简历 一年工作就有5年工作经验 你只需要这三个技能...
  3. 最懂选择的人用这4种策略避免纠结
  4. python历史波动率_【BSM模型】用实际市场数据计算隐含波动率并验证波动率微笑...
  5. [嵌入式开发模块]AD转换芯片ADS8344驱动模块
  6. Unity 2D平面显示3D模型(RenderTextrue)
  7. 作为一个研发背景出身的项目经理写给IT面试者的几点建议
  8. 随便小计:MRP元素参与计算标准配置
  9. oracle的product删除不了,Linux下删除Oracle实例
  10. IT界6个国内技术大牛博客,全栈工程师修行的秘籍!