CF1200E.Compress Words

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Amugae has a sentence consisting of nn words. He want to compress this sentence into one word. Amugae doesn't like repetitions, so when he merges two words into one word, he removes the longest prefix of the second word that coincides with a suffix of the first word. For example, he merges "sample" and "please" into "samplease".

Amugae will merge his sentence left to right (i.e. first merge the first two words, then merge the result with the third word and so on). Write a program that prints the compressed word after the merging process ends.
Amugae 有一个由 nn 个单词组成的句子。他想把这个句子压缩成一个词。阿木江不喜欢重复,所以当他把两个词合并成一个词时,他会去掉第二个词中与第一个词的后缀重合的最长前缀。例如,他将 "sample "和 "please "合并为 "samplease"。

Amugae 将从左到右合并他的句子(即先合并前两个词,然后将结果与第三个词合并,依此类推)。请编写一个程序,在合并过程结束后打印出压缩后的单词。

输入格式

The first line contains an integer nn ( 1n1051 \le n \le 10^5 ), the number of the words in Amugae's sentence.

The second line contains nn words separated by single space. Each words is non-empty and consists of uppercase and lowercase English letters and digits ('A', 'B', ..., 'Z', 'a', 'b', ..., 'z', '0', '1', ..., '9'). The total length of the words does not exceed 10610^6 .
输入

第一行包含一个整数 nn ( 1n1051 \le n \le 10^5 ),即 Amugae 句子中的单词数。

第二行包含 nn 个单词,单词之间用空格隔开。每个单词都不是空的,由大写、小写英文字母和数字('A', 'B', ..., 'Z', 'a', 'b', ..., 'z', '0', '1', ..., '9')组成。单词的总长度不超过 10610^6

输出格式

In the only line output the compressed word after the merging process ends as described in the problem.
输出

在唯一一行中,输出合并过程结束后的压缩字,如问题所述。

输入输出样例

  • 输入#1

    5
    I want to order pizza
    

    输出#1

    Iwantorderpizza
  • 输入#2

    5
    sample please ease in out
    

    输出#2

    sampleaseinout
首页