CCO '10 P6 - Shuffle

View as PDF

Submit solution

Points: 10
Time limit: 1.0s
Memory limit: 1G

Problem type
Canadian Computing Competition: 2010 Stage 2, Day 2, Problem 3

You want to keep some secrets, so you invent a simple encryption algorithm.

You will map each uppercase character and underscore to some other uppercase character and underscore. In other words, this is a permutation of the characters, or, to put it another way, you create a 1:1 and onto map from \{A, B, \dots, Z, \_\ \} to \{A, B, \dots, Z, \_\ \}.

However, you will repeatedly apply this encryption in an attempt to make your message more secure.

Input Specification

The input will be 29 lines long. The first 27 lines will each contain a single character from the set \{A, B, \dots, Z, \_\ \}. The first of these lines represents what the character A maps to, the second of these lines represents what the character B maps to, and so on, until the 27^{th} line represents what the underscore character maps to. On the 28^{th} line will be an integer N (1 \le N \le 2\,000\,000\,000) which represents the number of times this encryption should be applied. On the 29^{th} line is T, a string of less than 90 characters from the set \{A, B, \dots, Z, \_\ \}.

Output Specification

On one line, output the string created after shuffling T a total of N times, using the given shuffle permutation.

Sample Input

B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
_
A
3
I_LOVE_THE_CCC

Sample Output

LCORYHCWKHCFFF

Comments


  • 0
    TheZombieCloud  commented on June 14, 2017, 3:55 p.m.

    Unique

    Is every character's mapping unique? For example, some random character gets mapped to A, but another random character cannot get mapped to A.


    • 2
      Xue_Alex  commented on June 14, 2017, 3:58 p.m.

      Yes, each character's mapping is unique, if it weren't then some characters wouldn't be able to be mapped to.