CF95A.Hockey

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Petya loves hockey very much. One day, as he was watching a hockey match, he fell asleep. Petya dreamt of being appointed to change a hockey team's name. Thus, Petya was given the original team name w and the collection of forbidden substrings _s_1, _s_2, ..., s__n. All those strings consist of uppercase and lowercase Latin letters. String w has the length of |w|, its characters are numbered from 1 to |w|.

First Petya should find all the occurrences of forbidden substrings in the w string. During the search of substrings the case of letter shouldn't be taken into consideration. That is, strings "aBC" and "ABc" are considered equal.

After that Petya should perform the replacement of all letters covered by the occurrences. More formally: a letter in the position i should be replaced by any other one if for position i in string w there exist pair of indices l, r (1 ≤ l ≤ i ≤ r ≤ |w|) such that substring w[l ... r] is contained in the collection _s_1, _s_2, ..., s__n, when using case insensitive comparison. During the replacement the letter's case should remain the same. Petya is not allowed to replace the letters that aren't covered by any forbidden substring.

Letter letter (uppercase or lowercase) is considered lucky for the hockey players. That's why Petya should perform the changes so that the letter occurred in the resulting string as many times as possible. Help Petya to find such resulting string. If there are several such strings, find the one that comes first lexicographically.

Note that the process of replacements is not repeated, it occurs only once. That is, if after Petya's replacements the string started to contain new occurrences of bad substrings, Petya pays no attention to them.

佩佳非常喜欢冰球。一天,他在观看一场冰球比赛时睡着了。佩佳梦见自己被委派更改一支冰球队的队名。于是,佩佳得到了原始队名 ww 以及一组禁用子串 s1, s2, …, sns_1,\ s_2,\ \dots,\ s_n。所有这些字符串均由大小写拉丁字母组成。字符串 ww 的长度为 ∣w∣|w|,其字符编号从 11 到 ∣w∣|w|。

首先,佩佳需找出字符串 ww 中所有禁用子串的出现位置。在搜索子串时,不区分大小写。即,字符串 "aBC" 和 "ABc" 被视为相等。

接着,佩佳需替换所有被禁用子串覆盖的字母。更准确地说:若对字符串 ww 中位置 ii 存在一对下标 l, rl,\ r(满足 1≤l≤i≤r≤∣w∣1\le l\le i\le r\le |w|),使得子串 w[l…r]w[l \dots r] 在集合 {s1, s2, …, sn}\{s_1,\ s_2,\ \dots,\ s_n\} 中(按不区分大小写的比较方式),则位置 ii 上的字母必须被替换成任意其他字母。替换过程中,字母的大小写必须保持不变。佩佳不允许替换未被任何禁用子串覆盖的字母。

字母 letter(无论大小写)对冰球运动员而言是幸运的。因此,佩佳需进行上述替换,使得该 letter 在最终字符串中出现次数尽可能多。请帮助佩佳找到这样的最终字符串。若存在多个满足条件的字符串,则输出其中字典序最小的一个。

注意:替换过程仅执行一次,不重复进行。即,若佩佳完成替换后,字符串中又出现了新的禁用子串,佩佳也不予理会。

输入格式

The first line contains the only integer n (1 ≤ n ≤ 100) — the number of forbidden substrings in the collection. Next n lines contain these substrings. The next line contains string w. All those n + 1 lines are non-empty strings consisting of uppercase and lowercase Latin letters whose length does not exceed 100. The last line contains a lowercase letter letter.

第一行包含唯一一个整数 nn(1≤n≤1001 \leq n \leq 100)—— 表示集合中禁止子串的个数。接下来的 nn 行包含这些禁止子串。再下一行包含字符串 ww。这 n+1n+1 行均为非空字符串,仅由大小写拉丁字母组成,且每行长度均不超过 100。最后一行包含一个小写字母 letterletter。

输出格式

Output the only line — Petya's resulting string with the maximum number of letters letter. If there are several answers then output the one that comes first lexicographically.

The lexicographical comparison is performed by the standard < operator in modern programming languages. The line a is lexicographically smaller than the line b, if a is a prefix of b, or there exists such an i (1 ≤ i ≤ |a|), that a__i < b__i, and for any j (1 ≤ j < i) a__j = b__j. |a| stands for the length of string a.

输出唯一一行——佩蒂亚得到的、包含最多字母 letter 的字符串。如果存在多个满足条件的答案,则输出字典序最小的那个。

字典序比较采用现代编程语言中的标准 < 运算符进行。字符串 a 的字典序小于字符串 b,当且仅当:a 是 b 的前缀;或者存在某个下标 i(1 ≤ i ≤ |a|),使得 a__i < b__i,且对任意 j(1 ≤ j < i)均有 a__j = b__j。其中 |a| 表示字符串 a 的长度。

输入输出样例

  • 输入#1

    3
    bers
    ucky
    elu
    PetrLoveLuckyNumbers
    t

    输出#1

    PetrLovtTttttNumtttt
  • 输入#2

    4
    hello
    party
    abefglghjdhfgj
    IVan
    petrsmatchwin
    a

    输出#2

    petrsmatchwin
  • 输入#3

    2
    aCa
    cba
    abAcaba
    c

    输出#3

    abCacba

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

首页