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
#include <stdio.h>
#include <string.h> int next[100005]; void getnext(char str[])
{
int i = 1,j = 0;
int len = strlen(str);
next [0] = -1;
while(i < len)
{
if(j == -1 || str[i] == str[j])
{
i++;
j++;
next[i] = j;
}
else
j = next[j];
}
} int kmp(char str1[],char str2[])
{
int i= 0,j = 0;
int len1 = strlen(str1),len2 = strlen(str2);
getnext(str2);
while(i<len1 && j<len2)
{
if(j == -1 || str1[i] == str2[j])
{
i++;
j++;
}
else
j = next[j];
}
if(i == len1)
return j;
return 0;
} int main()
{
int x,y;
char str1[100005],str2[100005];
while(scanf("%s%s",str1,str2)!=EOF)
{
x = kmp(str1,str2);
y = kmp(str2,str1);
if(x == y)
{
if(strcmp(str1,str2)>0)
{
printf("%s",str2);
printf("%s\n",str1+x);
}
else
{
printf("%s",str1);
printf("%s\n",str2+x);
}
}
else if(x>y)
{
printf("%s",str1);
printf("%s\n",str2+x);
}
else
{
printf("%s",str2);
printf("%s\n",str1+y);
}
} return 0;
}

最新文章

  1. 深入理解java内存模型系列文章
  2. 生产环境使用 pt-table-checksum 检查MySQL数据一致性
  3. 【JS】键盘鼠标事件
  4. java web的开发 知识要点
  5. python环境
  6. 关于C语言和汇编语言相互嵌套调用
  7. virtualbox安装提示出现严重错误解决办法
  8. Oracle 10G (Linux) 冷备恢复
  9. 浅谈C51内存优化
  10. Visual Studio 启动加速
  11. slf4j+log4j配置(Maven)
  12. 一个分组查询 每组前 10 的sql 语句
  13. nyoj 47 江 河问题 【贪婪】
  14. WebService之CXF注解报错(一)
  15. Linux监控工具vmstat命令详解
  16. 前端开发规范:命名规范、html 规范、css 规范、js 规范
  17. [SDOI 2013]森林
  18. java 实现加密算法(在网上看的,保存)
  19. 利用 Windows API Code Pack 修改音乐的 ID3 信息
  20. 一步步Cobol 400上手自学入门教程06 - 子程序调用

热门文章

  1. “System.Runtime.InteropServices.COMException”类型的第一次机会异常在 ESRI.ArcGIS.Version.dll 中发生
  2. iOS 加入粘贴板的功能(复制功能)
  3. ROS探索总结(十九)——怎样配置机器人的导航功能
  4. ZOJ 1654--Place the Robots【二分匹配 &amp;amp;&amp;amp; 经典建图】
  5. poj2750--Potted Flower(线段树)
  6. Running the app on your device
  7. div内容上下左右居中
  8. python 读取二进制文件 转为16进制输出
  9. docker(部署常见应用):docker部署redis
  10. Pinpoint 监控