Codeforces 95A-Hockey
来源:互联网 发布:外汇分析软件哪个好 编辑:程序博客网 时间:2024/04/29 21:29
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.
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 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.
3bersuckyeluPetrLoveLuckyNumberst
PetrLovtTttttNumtttt
4hellopartyabefglghjdhfgjIVanpetrsmatchwina
petrsmatchwin
2aCacbaabAcabac
abCacba
#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;}
- Codeforces 95A-Hockey
- OPENGL|ES 第二天,A Simple Game of Air Hockey
- CodeForces-a
- 1736. Chinese Hockey
- Codeforces 903A A
- CodeForces 18A A - Triangle
- CodeForces 133A A. HQ9+
- codeforces 651A A. Joysticks
- 【Codeforces 597A】A. Divisibility
- 【 Codeforces 615A】A. Bulbs
- A. Divisibility CodeForces 597A
- codeforces 417A A. Elimination
- CodeForces 534A A. Exam
- codeforces#98 a
- codeforces#99 a
- codeforces 105 div2 A
- codeforces #121 A
- Codeforces 185A Plant
- 前端 UEditor编辑器插入到textarea文本框流程简单介绍
- 触摸屏拓展屏软件(自定义界面)
- mac 下安装多版本jdk 以及切换方式
- 关于\r\n和\n程序员应了解的实际应用
- 嵌入式开发之c基础第二天学习笔记
- Codeforces 95A-Hockey
- Servlet 根据浏览器的头信息判断使用的是什么浏览器,(兼容性比较常使用)
- jquery 表单清空
- JAVA语言基础 +JAVA学习笔记-DAY04
- 三天上手PHP之13:表单(form)
- NGUI诡异的drawCall
- JZOJ4823. 【NOIP2016提高A组集训第1场10.29】小W学物理
- bzoj 1012: [JSOI2008]最大数maxnumber
- Log.xml文件配置