博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDUOJ---1867 A + B for you again
阅读量:6341 次
发布时间:2019-06-22

本文共 1610 字,大约阅读时间需要 5 分钟。

A + B for you again

Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3432    Accepted Submission(s): 869

Problem Description
Generally speaking, there are a lot of problems about strings processing. Now you encounter another such problem. If you get two strings, such as “asdf” and “sdfg”, the result of the addition between them is “asdfg”, for “sdf” is the tail substring of “asdf” and the head substring of the “sdfg” . However, the result comes as “asdfghjk”, when you have to add “asdf” and “ghjk” and guarantee the shortest string first, then the minimum lexicographic second, the same rules for other additions.
 
Input
For each case, there are two strings (the chars selected just form ‘a’ to ‘z’) for you, and each length of theirs won’t exceed 10^5 and won’t be empty.
 
Output
Print the ultimate string by the book.
 
Sample Input
asdf sdfg
asdf ghjk
 
Sample Output
asdfg
asdfghjk
 
Author
Wang Ye
 
简述一下题目的意思:对于s和t两个串,将这两个串合并为一个串,但是要满足下面的 规则:
比如: 如果s串在前,t在后, 且s串后缀和t串的前缀有重合的部分,合并这部分....比如 sdsds  sdsa  -->  sdsdsa
但是要满足下面的要求:
s和t 随意组合,可以s在前,t在后,亦可以t在前s在后,但是必须报保证s+t的串长度最小,若果两者组合的长度相等,则按照字典序的顺序组合输出....
比如 abc  cdea   -->abcdea
对此,我们可以用kmp来ac就可以了...
代码如下:
1 #include 
2 #include
3 #define maxn 100000 4 int next[maxn+1]; 5 char ps[maxn+1],pt[maxn+1]; 6 void get_next(char const * t,int *next,int const lent) 7 { 8 int i=0,j=-1; 9 memset(next,0,sizeof(next));10 next[0]=-1;11 while(i
ansb)57 {58 printf("%s",ps);59 for(i=ansa;i
View Code

 

 
Recommend

转载地址:http://dnhoa.baihongyu.com/

你可能感兴趣的文章
HDU-1394-Minimum Inversion Number
查看>>
[转] createObjectURL方法 实现本地图片预览
查看>>
JavaScript—DOM编程核心.
查看>>
JavaScript碎片
查看>>
Bootstrap-下拉菜单
查看>>
soapUi 接口测试
查看>>
【c学习-12】
查看>>
工作中MySql的了解到的小技巧
查看>>
loadrunner-2-12日志解析
查看>>
C# Memcached缓存
查看>>
正则表达式
查看>>
mysql [ERROR] Can't create IP socket: Permission denied
查看>>
PBRT笔记(4)——颜色和辐射度
查看>>
CustomView的手势缩放总结
查看>>
linux复制指定目录下的全部文件到另一个目录中,linux cp 文件夹
查看>>
CentOS yum安装mysql
查看>>
OceanBase笔记1:代码规范
查看>>
[Algorithms] Longest Increasing Subsequence
查看>>
MAC下GitHub命令操作
查看>>
springboot之filter/listener/servlet
查看>>