HDU 1867:A + B for you again
2015-07-30 15:47
423 查看
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; char a[100001],b[100001]; int nextd[100001]; void get(char *ch) { int s=0,t=-1; nextd[0]=-1; int l=strlen(ch); while(s<l) { if(t==-1||ch[s]==ch[t]) { s++; t++; nextd[s]=t; } else t=nextd[t]; } } int KMP(char *ch1,char *ch2) { get(ch2); int s=0,t=0; int l1=strlen(ch1); int l2=strlen(ch2); while(s<l1) { if(t==-1||ch1[s]==ch2[t]) { s++; t++; } else t=nextd[t]; } return t; } int main() { int i,j,k,n,m,l; while(~scanf("%s %s",a,b)) { int l1=KMP(a,b); int l2=KMP(b,a); if(l1==l2) { if(strcmp(a,b)>0) { printf("%s%s\n",b,a+l1); } else { printf("%s%s\n",a,b+l1); } } else if(l1>l2) { printf("%s%s\n",a,b+l1); } else { printf("%s%s\n",b,a+l2); } } return 0; }
相关文章推荐
- 非阻塞connect() http://blog.csdn.net/shellching/article/details/7663086
- getopt() http://blog.csdn.net/kunikida/article/details/8922402
- Core Animaiton - 8
- HDU 1021 Fibonacci Again
- ubuntu sendmail 发送邮件
- 象棋AI算法(二)
- main真正的形状函数
- SVN commit:remains in tree-conflict错误的解决办法
- details
- Handler sendMessage 与 obtainMessage (sendToTarget)比较
- 有关人工智能的假设
- HDU 1022 Train Problem I
- UVALive 6800 The Mountain of Gold (bellman_ford判负环)
- uva 11374 Airport Express(最短路)
- DataBinder.Eval和Container.DataItem(DataRowView)有什么区别
- Open-air shopping malls(二分半径,两元交面积)
- 基于CLM(Constrained local model)人脸点检测算法
- Easy 2048 Again - ZOJ 3802 像缩进dp
- 怎么提高RailS应用的性能
- Rails项目中避免滥用这三种特性