hdu1867A + B for you again
#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的更多相关文章
随机推荐
- Android 学习笔记(一)
环境配置在网上搜索的一大堆. 这里简单发几个连接. http://jingyan.baidu.com/article/bea41d437a41b6b4c51be6c1.html http://jing ...
- Json.Net序列化和反序列化设置
首先补充一点,Json.Net是支持序列化和反序列化DataTable,DataSet,Entity Framework和NHibernate的.我举例说明DataTable的序列化和反序列化.创建一 ...
- oracle函数trunc的使用
1.日期比较时精确到日,可以使用 TRUNC(sysdate,'dd')函数.函数支持格式有:yyyy MM dd hh Mi可以用 select TRUNC(sysdate,'yyyy') ...
- JS 之 innerHTML
定义和用法 innerHTML 属性用于设置或返回指定标签之间的 HTML 内容. 语法 Object.innerHTML = "HTML";// 设置 var html = Ob ...
- BZOJ 3368 约翰看山(扫描)O(N)
这题,简直丧心病狂了. 大意是给你一个环上一些覆盖的区间,让你求总覆盖长度. 非常坑的点是这个区间因为是个环,所以可能逆时针给你,也可能顺时针给你,你特别要注意.那么区分顺时针和逆时针的方法 就是,题 ...
- uva 123 Searching Quickly
Searching Quickly Background Searching and sorting are part of the theory and practice of computer ...
- windows查询端口
依次点击“开始→运行”,键入“cmd”并回车,打开命令提示符窗口.在命令提示符状态下键入“netstat -an”,按下回车键后就可以看到以数字形式显示的TCP和UDP连接的端口号及状态.
- Git 分支管理详解
大纲: 1.前言 2.创建分支 3.切换分支 4.合并分支(快速合并) 5.删除分支 6.分支合并冲突 7.合并分支(普通合并) 8.分支管理策略 9.团队多人开发协作 10.总结 注,测试机 Cen ...
- 简单的JQuery top返回顶部
一个最简单的JQuery Top返回的代码,Mark一下: HTML如下: <div id="backtop"> <a href="javascript ...
- Java Thread 总结
目 录 线程的概述(Introduction) 线程的定义(Defining) 1) 继承java.lang.Thread类 2) 实现java.lang.Runnable接口 线程的启动(St ...