Codeforces 95A-Hockey

来源:互联网 发布:外汇分析软件哪个好 编辑:程序博客网 时间:2024/04/29 21:29

Hockey
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 s1, s2, ..., sn. 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 s1, s2, ..., sn, 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.

Input

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.

Output

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 ai < bi, and for any j (1 ≤ j < i)aj = bj|a| stands for the length of string a.

Examples
input
3bersuckyeluPetrLoveLuckyNumberst
output
PetrLovtTttttNumtttt
input
4hellopartyabefglghjdhfgjIVanpetrsmatchwina
output
petrsmatchwin
input
2aCacbaabAcabac
output
abCacba
题意:给出n个禁止子字符串和字符串w。所有这些字符串由大写和小写拉丁字母组成。在w字符串中找到所有出现的禁止子字符串。在搜索子字符串时,不应考虑字母的情况。然后替换出现的字母。不允许替换没有被任何禁止子字符串覆盖的字母。给出字母x(大写或小写),字母x被认为是幸运的。替换后字母x在结果字符串中出现尽可能多的次数。找到这样生成的字符串。如果有几个这样的字符串,找到按字典顺序的第一个。替换的过程不重复,它只发生一次。也就是说,如果在替换之后,字符串开始包含新出现的禁止子字符串,则跳过。

#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <string>#include <algorithm>#include <queue>#include <stack>#include <map>using namespace std;int n;char s[200][200],ch[200],x,ch1[200];int main(){    while(~scanf("%d",&n))    {        for(int i=0; i<n; i++)            scanf("%s",s[i]);        scanf("%s",ch);        getchar();        scanf("%c",&x);        strcpy(ch1,ch);        for(int i=0; i<n; i++)        {            int p=strlen(ch)-strlen(s[i]);            for(int j=0; j<=p; j++)            {                int k1=j,k2=0;                while((ch[k1]==s[i][k2]||ch[k1]-s[i][k2]==32||s[i][k2]-ch[k1]==32)&&k2<strlen(s[i]))                    k1++,k2++;                if(k2>=strlen(s[i]))                {                    for(int k=j; k<j+strlen(s[i]); k++)                        ch1[k]='\t';                }            }        }        for(int i=0; i<strlen(ch); i++)        {            if(ch1[i]!='\t') printf("%c",ch[i]);            else            {                if(ch[i]==x||x-ch[i]==32||ch[i]-x==32)                {                    if(ch[i]=='A')                        printf("%c",'B');                    else if(ch[i]=='a')                        printf("%c",'b');                    else if(ch[i]>='B'&&ch[i]<='Z')                        printf("%c",'A');                    else if(ch[i]>='b'&&ch[i]<='z')                        printf("%c",'a');                }                else if(ch[i]>='A'&&ch[i]<='Z')                {                    if(x>='a'&&x<='z') printf("%c",x-32);                    else printf("%c",x);                }                else                {                    if(x>='a'&&x<='z') printf("%c",x);                    else printf("%c",x+32);                }            }        }        printf("\n");    }    return 0;}

0 0
原创粉丝点击