WOSS Dual Olympiad 2022 J3/S1: Christmas List

View as PDF

Submit solution

Points: 5 (partial)
Time limit: 2.0s
Memory limit: 256M

Authors:
Problem type

With Christmas rapidly approaching, you have planned gifts for your friends and secured a Christmas tree. However, you cannot forget about your own gift! You have created a wishlist consisting of N items, but the only problem is that it is encoded. You hid the cipher in the CS Club classroom and have now retrieved it. The cipher is a 5 by 5 grid consisting of lowercase letters formatted like the one given below.

1 2 3 4 5
A q w a r t
B y u i o p
C e s d f g
D h j k l x
E c v b n m

The coded version of a character consists of its coordinates like so: [letter, number]. For example, the coded version of the letter b would be E3. By this logic, words can be coded and decoded. For example, the word bike would be E3B3D3C1 when encoded. Note that any cipher will always contain 25 letters, meaning that one letter will always be missing. This excluded letter will not be encoded in the list. For example, E3zB3D3C1 would translate to bzike.

Your job is to create a program that, given the cipher in the form of a 5 by 5 grid and the coded wishlist, will output the decoded version of all N items on the list.

Constraints

1 \le N \le 1\,000

2 \le \text{length}(S) \le 100

Note: It is guaranteed that all strings S will be decodable using the given cipher and set of rules in the problem statement.

Subtask 1 [40%]

The items in the list will not contain the excluded letter from the cipher.

Subtask 2 [60%]

No additional constraints.

Input Specification

The first line will contain a single integer, N, representing the number of items on your wishlist.

The next five lines will contain the cipher: each line will contain five space-separated characters representing a row of the grid.

The next N lines of input will each contain a string S, representing an encoded version of an item on your wishlist.

Output Specification

The output should consist of N lines: the ith line of output should contain a string representing the decoded version of the ith item on the wishlist.

Sample Input

Note: You will not be required to pass this sample case to progress to the subtasks.

4
q w a r t
y u i o p
e s d f g
h j k l x
c v b n m
E3B3D3C1
E2B3C3C1B4C5A3E5C1
C2A2C1A3A5C1A4
E3zB3D3C1

Sample Output

bike
videogame
sweater
bzike

Explanation of Sample

The cipher given in this case corresponds to the example given in the problem statement. Using the coding system explained shows that each decoded version corresponds to the coded ones in the input.


Comments

There are no comments at the moment.