`
hunxiejun
  • 浏览: 1148123 次
文章分类
社区版块
存档分类
最新评论

杭电 1867 KMP连接两个字符串

 
阅读更多

悲剧,,已经记不清写这道题写了几天了,,,,总之就是一直不断的wr,,,然后一直不断的找漏洞,,,,刚才才明白,,原来调用KMP函数时,,j的值就是匹配的长度,,,而我之前却在绞尽脑汁的想这么求匹配的长度。。。。。。。这让我情何以堪!!!!!!!!!!用两次KMP,比较一下两次匹配长度即可。题目:

A + B for you again

Time Limit: 5000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1336Accepted Submission(s): 288


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

ac代码:



分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics