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
 
Source
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath> using namespace std; char s1[],s2[],s3[],s4[];
int nextt[];
int match[]; int main()
{
int i,j,k;
while(scanf("%s%s",s1+,s2+)!=EOF)
{
int l1 = strlen(s1+),l2 = strlen(s2+);
nextt[] = ;
for(i = ;i<=l2;i++)
{
int t = nextt[i-];
while(t&&s2[i]!=s2[t+]) t = nextt[t];
if(s2[i] == s2[t+]) t++;
nextt[i] = t;
}
match[] = ;
for(i = ;i<=l1;i++)
{
int t = match[i-];
while(t&&s1[i]!=s2[t+]) t = nextt[t];
if(s1[i] == s2[t+]) t++;
match[i] = t;
}
int t1 = match[l1];
for(i = ;i<=l1;i++)
s3[i] = s1[i];
for(i = l1+;i<=l1+l2-t1+;i++)
s3[i] = s2[i-l1+t1];
nextt[] = ;
for(i = ;i<=l1;i++)
{
int t = nextt[i-];
while(t&&s1[i]!=s1[t+]) t = nextt[t];
if(s1[i] == s1[t+]) t++;
nextt[i] = t;
}
match[] = ;
for(i = ;i<=l2;i++)
{
int t = match[i-];
while(t&&s2[i]!=s1[t+]) t = nextt[t];
if(s2[i] == s1[t+]) t++;
match[i] = t;
}
int t2 = match[l2];
for(i = ;i<=l2;i++)
s4[i] = s2[i];
for(i = l2+;i<=l2+l1-t2+;i++)
s4[i] = s1[i-l2+t2];
if(t1>t2) printf("%s",s3+);
else if(t2>t1) printf("%s",s4+);
else
{
int l = l1+l2-t2;
bool bb = ;
for(i = ;i<=l;i++)
{
if(s3[i]<s4[i])
{
printf("%s",s3+);
bb = ;
break;
}
else if(s3[i]>s4[i])
{
printf("%s",s4+);
bb = ;
break;
}
}
if(!bb) printf("%s",s3+);
}
puts("");
}
return ;
}

hdu1867A + B for you again的更多相关文章

随机推荐

  1. Android平台抓取native crash log

    Android开发中,在Java层可以方便的捕获crashlog,但对于 Native 层的 crashlog 通常无法直接获取,只能通过系统的logcat来分析crash日志. 做过 Linux 和 ...

  2. 转:APK反编译

    使用工具:      CSDN上下载地址: apktool (资源文件获取) 下载 dex2jar(源码文件获取) 下载 jd-gui (源码查看) 下载 Android反编译整合工具包(最新) 下载 ...

  3. Oracle 11g完全卸载(Windows)(转)

    Oracle 11g完全卸载(Windows) 1.关闭oracle所有的服务.可以在windows的服务管理器中关闭:    一般有以下服务:   (1)Oracle SID VSS Writer ...

  4. VB.NET 结构(Structure)和类(Class)的区别

    类是我们用来构造 VB.NET 应用程序时的最基本的编程结构了. 那结构与类有什么相似之处与不同之处呢? 结构和类, 相同之处是都含有成员,包括构造函数.方法.属性.字段.常量.枚举和事件,都可以实现 ...

  5. yum添加源。

    本文以centos 7为准.其他版本的linux可能存在一些偏差. 第一:索引文件. 1)repo文件. 1.repo文件是指以repo为结尾的文件.是 仓库源的索引文件.将其添加到yum的repo仓 ...

  6. [转]MFC 加载其他的应用程序

    三个SDK函数 winexec, shellexecute,createprocess可以使用.WinExec 最简单,两个参数,前一个指定路径,后一个指定显示方式.后一个参数值得说一下,比如泥用 S ...

  7. Python zxing 库解析(条形码二维码识别)

    各种扫码软件 最近要做个二维码识别的项目,查到二维码识别有好多开源的不开源的软件 http://www.oschina.net/project/tag/238/ Zbar 首先试了一下Zbar,pyt ...

  8. JAVA的网络编程【转】

    JAVA的网络编程[转] Posted on 2009-12-03 18:04 火之光 阅读(93441) 评论(20) 编辑 收藏 网络编程 网络编程对于很多的初学者来说,都是很向往的一种编程技能, ...

  9. ES5 object的新函数

    虽然说现在并不是所有的浏览器都已经支持ECMAScript5的新特性,但相比于ECMAScript4而言ECMAScript5被广大浏览器厂商广泛接受,目前主流的浏览器中只有低版本的IE不支持,其它都 ...

  10. 处理编译错误"0" is an invalid value for the "DebugInformation" parameter of the "DCC"

    在编译“MustangpeakCommonLib-master.zip”时,遇到了这个问题.网上搜了一下: 处理编译错误"0" is an invalid value for the "DebugIn ...