hdu 1867 kmp裸题
来源:互联网 发布:目标软件倒闭 编辑:程序博客网 时间:2024/06/05 00:09
题目链接如下:http://acm.hdu.edu.cn/showproblem.php?pid=1867
题意:将两个字符串加在一起,重复的部分只出现一次,长度越短优先,字典序越短优先,
思路:kmp 求出两个字符串做为各自字串kmp值,kmp有修改;
代码:
#include<iostream>#include<stdio.h>#include<string.h>#include<algorithm>#include<vector>#include<stack>#include<queue>#include<list>#include<string>using namespace std;const int maxn=222222;int next[maxn];void getnext(char x[]){ int i,j; int m=strlen(x); j=next[0]=-1; i=0; while(i<m) { while(j!=-1&&x[i]!=x[j])j=next[j]; next[++i]=++j; }}int kmp(char s[],char t[]){ int n=strlen(s); int m=strlen(t); getnext(t); int i,j; for(i=0,j=0;i<n&&j<m;) { if(j==-1||s[i]==t[j]) ++i,++j; else j=next[j]; } if(i>=n)return j; return 0;}int main(){ char s[maxn],t[maxn]; for(; ~scanf("%s%s",s,t);) { int x=kmp(s,t); int y=kmp(t,s); if(x==y) { if(strcmp(s,t)>0) { printf("%s",t); printf("%s\n",s+x); } else { printf("%s",s); printf("%s\n",t+x); } } else if(x>y) { printf("%s",s); printf("%s\n",t+x); } else { printf("%s",t); printf("%s\n",s+y); } } return 0;}
- hdu 1867 kmp裸题
- HDU 1867 KMP
- hdu 1867 KMP
- hdu 1867 (KMP)
- HDU--1867(KMP)
- hdu 1867 kmp匹配
- HDU 1867 KMP
- hdu 1711kmp裸题
- HDU 2087 KMP裸题
- hdu 1711 KMP裸题
- HDU - 1686 KMP裸题
- hdu 1867 链接字符串+kmp
- hdu 1686 Oulipo (KMP裸题)
- hdu 1867 史上最裸KMP 第二弹
- HDU 1867 KMP 求最大尾部重叠
- hdu 1867 Cow Patterns kmp模板
- HDU 1711 Number Sequence KMP裸题
- hdu 4333 kmp+扩展kmp
- Delphi图像处理
- 抽象类和接口不能直接实例化
- nosql mongodb 学习-----第二天 高级操作之查询命令
- Hibernate N+1问题
- 用例子理解synchronized
- hdu 1867 kmp裸题
- windows编程常见错误(1)playsound的错误
- LeetCode——Divide Two Integers
- 1381. a*b
- android 数据库 sqlite数据类型(时间 日期 double等)
- [JavaScript] 兼容IE、FireFox、Chrome等浏览器的xml处理函数(xml同步/异步加载、xsl转换、selectSingleNode、selectNodes)
- 论#pragma comment和winmm.lib函数(为什么palysound出现错误原因)
- 水仙花
- 实体框架(Entity Framework)简介