HDUOJ---1867 A + B for you again
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
#include <stdio.h>
#include <string.h>
#define maxn 100000
int next[maxn+];
char ps[maxn+],pt[maxn+];
void get_next(char const * t,int *next,int const lent)
{
int i=,j=-;
memset(next,,sizeof(next));
next[]=-;
while(i<lent)
{
if(j==-||t[i]==t[j])
{
++i;
++j;
if(t[i]!=t[j])
next[i]=j;
else
next[i]=next[j]; }
else
j=next[j];
}
} int ext_kmp(char const * ps, char const *pt,int const lens,int const lent)
{
int i=lens-lent-,j=-;
get_next(pt,next,lent);
if(i<-)i=-;
while(i<lens)
{
if(j==-||ps[i]==pt[j])
{
++i;
++j;
}
else
j=next[j];
}
return j;
} int main()
{
int i,ansa,ansb;
int lens,lent;
while(scanf("%s%s",ps,pt)!=EOF)
{
lens=strlen(ps);
lent=strlen(pt);
ansa=ext_kmp(ps,pt,lens,lent);
ansb=ext_kmp(pt,ps,lent,lens);
if(ansa>ansb)
{
printf("%s",ps);
for(i=ansa;i<lent;i++)
printf("%c",pt[i]);
}
else if(ansa<ansb)
{
printf("%s",pt);
for(i=ansb;i<lens;i++)
printf("%c",ps[i]);
}
else
{
if(strcmp(ps,pt)<)
{
printf("%s",ps);
for(i=ansa;i<lent;i++)
printf("%c",pt[i]);
}
else
{
printf("%s",pt);
for(i=ansb;i<lens;i++)
printf("%c",ps[i]);
}
}
putchar();
}
return ;
}
HDUOJ---1867 A + B for you again的更多相关文章
- hduoj 1455 && uva 243 E - Sticks
http://acm.hdu.edu.cn/showproblem.php?pid=1455 http://uva.onlinejudge.org/index.php?option=com_onlin ...
- hduoj 4712 Hamming Distance 2013 ACM/ICPC Asia Regional Online —— Warmup
http://acm.hdu.edu.cn/showproblem.php?pid=4712 Hamming Distance Time Limit: 6000/3000 MS (Java/Other ...
- hduoj 4706 Herding 2013 ACM/ICPC Asia Regional Online —— Warmup
hduoj 4706 Children's Day 2013 ACM/ICPC Asia Regional Online —— Warmup Herding Time Limit: 2000/1000 ...
- hdu 1867 A + B for you again
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1867 A + B for you again Description Generally speaki ...
- HIT 1867 经理的烦恼
题目链接:http://acm.hit.edu.cn/hoj/problem/view?id=1867 每次更新时判断是否素数,如果从非素数变成素数就Update(x, 1),如果从素数变成非素数就U ...
- hdu-oj 1874 畅通工程续
最短路基础 这个题目hdu-oj 1874可以用来练习最短路的一些算法. Dijkstra 无优化版本 #include<cstdio> #include<iostream> ...
- C#版 - HDUoj 5391 - Zball in Tina Town(素数) - 题解
版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. HDUoj 5 ...
- C++版 - HDUoj 2010 3阶的水仙花数 - 牛客网
版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. C++版 - ...
- HDUOJ题目HTML的爬取
HDUOJ题目HTML的爬取 封装好的exe/app的GitHub地址:https://github.com/Rhythmicc/HDUHTML 按照系统选择即可. 其实没什么难度,先爬下来一个题目的 ...
- HDU - 4535 ZZULI 1867: 礼上往来【错位排序】
1867: 礼上往来 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 216 Solved: 65 SubmitStatusWeb Board Desc ...
随机推荐
- Oracle 10g AND Oracle 11g手工建库案例--Oracle 10g
Oracle 10g AND Oracle 11g手工建库案例--Oracle 10g 系统环境: 操作系统: RedHat EL6 Oracle: Oracle 10g and Oracle 11 ...
- 如何判断一个文本文件内容的编码格式 UTF-8 ? ANSI(GBK)
转自:http://blog.csdn.net/jiangqin115/article/details/42684017 UTF-8编码的文本文档,有的带有BOM (Byte Order Mark, ...
- jquery json实现二级动态联动
以下为代码!需要导入json架包 function getCity1(){ var unitid = document.getElementById('addformunitid').value; $ ...
- go语言进阶之为结构体类型添加方法
1.为结构体类型添加方法 示例: package main import "fmt" type Person struct { name string //名字 sex byte ...
- Longest Valid Parentheses leetcode java
题目: Given a string containing just the characters '(' and ')', find the length of the longest valid ...
- OpenGL使用libPng读取png图片
#include<stdarg.h> #include<png.h> #include<glut.h> #include<math.h> #includ ...
- scala多线程
object Test { def main(args: Array[String]) { //创建线程池 val threadPool:ExecutorService=Executors.newFi ...
- COM的一些基本概念
Windows lets you share code at the binary level using DLLs. After all, that's how Windows apps fun ...
- [ kvm ] 四种简单的网络模型
1. 隔离模式:虚拟机之间组建网络,该模式无法与宿主机通信,无法与其他网络通信,相当于虚拟机只是连接到一台交换机上. 2. 路由模式:相当于虚拟机连接到一台路由器上,由路由器(物理网卡),统一转 ...
- 使用Fiddler抓包调试https下的页面
众所周知https技术诞生以来,一个很重要的作用就是加密通信内容.所以在项目团队将业务站点实施完https改造以后,原先使用fiddler进行抓包的美好生活到头了.其实fiddler本身是支持对于ht ...