codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

95A.md (3241B)


      1 Source: https://codeforces.com/problemset/problem/95/A
      2 
      3 A. Hockey
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 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*|.
     22 
     23 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.
     24 
     25 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.
     26 
     27 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.
     28 
     29 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.
     30 
     31 Input
     32 
     33 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*.
     34 
     35 Output
     36 
     37 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.
     38 
     39 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*.
     40 
     41 Examples
     42 
     43 Input
     44 
     45 ```
     46 3  
     47 bers  
     48 ucky  
     49 elu  
     50 PetrLoveLuckyNumbers  
     51 t
     52 ```
     53 
     54 Output
     55 
     56 ```
     57 PetrLovtTttttNumtttt
     58 ```
     59 
     60 Input
     61 
     62 ```
     63 4  
     64 hello  
     65 party  
     66 abefglghjdhfgj  
     67 IVan  
     68 petrsmatchwin  
     69 a
     70 ```
     71 
     72 Output
     73 
     74 ```
     75 petrsmatchwin
     76 ```
     77 
     78 Input
     79 
     80 ```
     81 2  
     82 aCa  
     83 cba  
     84 abAcaba  
     85 c
     86 ```
     87 
     88 Output
     89 
     90 ```
     91 abCacba
     92 ```