我是靠谱客的博主 虚拟学姐,最近开发中收集的这篇文章主要介绍hdu1867A + B for you again(kmp) 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): 5925 Accepted Submission(s): 1469
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
2008杭电集训队选拔赛——热身赛
Recommend
lcy | We have carefully selected several similar problems for you:
1866
1277
1358
1865
2057
题意:
将两个字符串合并将匹配的字符串删去按字符串的字典数小的输出;
#include<stdio.h>
#include<string.h>
int next[100005];
void NEW(char b[])//子串的next
{
int i,q=0;
next[0]=0;
int m1;
m1=strlen(b);
for(i=1;i<m1;i++)
{
while(q>0&&b[q]!=b[i])
q=next[q-1];
if(b[q]==b[i])
q++;
next[i]=q;
}
}
int xiao(char a[],char b[])
{
int i;
NEW(b);
int q=0;
int m=strlen(a);
for(i=0;i<m;i++)
{
while(q>0&&a[i]!=b[q])
q=next[q-1];
if(a[i]==b[q])
q++;
}
return q;
}//母函数模板。
int main()
{
char a[100005],b[100005];
while(~scanf("%s%s",a,b))
{
int m,n;
m=xiao(a,b);
n=xiao(b,a);//比较出那个匹配的最少。
if(m==n)//
{
if(strcmp(a,b)>0)//相等的会看哪个在前面使字典数较小。
{
printf("%s",b);
printf("%sn",a+m);
}
else
{
printf("%s",a);
printf("%sn",b+m);
}
}
else if(m>n)//比较出那个匹配使字符串较短。
{
printf("%s",a);
printf("%sn",b+m);
}
else
{
printf("%s",b);
printf("%sn",a+n);
}
}
return 0;
}
#include<string.h>
int next[100005];
void NEW(char b[])//子串的next
{
int i,q=0;
next[0]=0;
int m1;
m1=strlen(b);
for(i=1;i<m1;i++)
{
while(q>0&&b[q]!=b[i])
q=next[q-1];
if(b[q]==b[i])
q++;
next[i]=q;
}
}
int xiao(char a[],char b[])
{
int i;
NEW(b);
int q=0;
int m=strlen(a);
for(i=0;i<m;i++)
{
while(q>0&&a[i]!=b[q])
q=next[q-1];
if(a[i]==b[q])
q++;
}
return q;
}//母函数模板。
int main()
{
char a[100005],b[100005];
while(~scanf("%s%s",a,b))
{
int m,n;
m=xiao(a,b);
n=xiao(b,a);//比较出那个匹配的最少。
if(m==n)//
{
if(strcmp(a,b)>0)//相等的会看哪个在前面使字典数较小。
{
printf("%s",b);
printf("%sn",a+m);
}
else
{
printf("%s",a);
printf("%sn",b+m);
}
}
else if(m>n)//比较出那个匹配使字符串较短。
{
printf("%s",a);
printf("%sn",b+m);
}
else
{
printf("%s",b);
printf("%sn",a+n);
}
}
return 0;
}
最后
以上就是虚拟学姐为你收集整理的hdu1867A + B for you again(kmp) A + B for you again的全部内容,希望文章能够帮你解决hdu1867A + B for you again(kmp) A + B for you again所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复