CF1200E.Compress Words

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

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 个单词组成的句子。他想将该句子压缩为一个单词。Amugae 不喜欢重复,因此当他把两个单词合并为一个单词时,他会删去第二个单词的、与第一个单词的后缀相匹配的最长前缀。例如,他将 “sample” 和 “please” 合并为 “samplease”。

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

输入格式

The first line contains an integer nn (1≤n≤1051 \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(1≤n≤1051 \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

输入解题思路,AI测评打分。不知道怎么写?

首页