COCI '16 Contest 4 #2 Kartomat

View as PDF

Points: 5 (partial)
Time limit: 1.0s
Memory limit: 32M

Problem type

A ticket machine is a device similar to an ATM and was introduced by Croatian Railways in order to make purchasing train tickets easier. The first step in buying a ticket is choosing the destination of your journey. The destination can be one of destinations offered in advance, names of local and worldwide places. You choose your destination by typing its name letter by letter. By entering each additional letter, the number of possible destinations reduces.

The initial appearance of the keyboard on the screen is shown in the picture. We will represent it as four arrays of characters of length .

***ABCDE
FGHIJKLM
NOPQRSTU
VWXYZ***

After choosing each letter, the keyboard changes its appearance. Only letters that can be chosen in the next step are left active (depending on the destinations still possible to choose). The remaining letters that can't be chosen are replaced with the character *.

Write a programme that will, for given destinations and the first few letters (not all of them) of the chosen destination, output the appearance of the keyboard before entering the next letter. You will never be given the entire word.

Input Specification

The first line contains the integer from the task. Each of the following lines contains one string of at most characters that contains only uppercase letters of the English alphabet. The last line contains the string that represents the first few letters of the chosen destination.

Output Specification

You must output the appearance of the keyboard described in the task.

Sample Input 1

4
ZAGREB
SISAK
ZABOK
ZA

Sample Output 1

****B*D*
*G******
********
********

Explanation for Sample Output 1

After entering the letters ZA, the third letter can be G if we want a ticket to Zagreb, D if we want a ticket to Zadar, and B if we want a ticket to Zabok.

Sample Input 2

4
SPLIT
VINKOVCI
NOVSKA
RIJEKA
VINKO

Sample Output 2

********
********
********
V*******

Sample Input 3

4
AAAABCD
AAAABCA
AAAACDE
AAAAAAA
AAAA

Sample Output 3

***ABC**
********
********
********