Dimitri is a cryptographer who developed a very simple algorithm for creating hashes. The algorithm works as follows:
- Each symbol corresponds to another symbol in a table
- There are three corresponding tables
- The hashing rule is simple:
- Every original symbol (ex. examplestring) is replaced with the corresponding one from the first table
- After that, every second symbol (ex. examplestring) is replaced with the corresponding one from the second table
- Then every third symbol (ex. examplestring) is replaced with the corresponding one from the third table
- If the symbol is not in the table, which you are currently working with, continue to the next table.
- Each corresponding symbol is given on a single line in the following format:
{before} -> {after}
- The first table will be read until you get
STOP
on single line - The second table will be read until you get
HALT
on single line - The third table will be read until you get
END
on single line - The tables are given in random order. You need to rely on the ending line to figure out which table you're currently reading (e.g.
STOP
orHALT
). - After all the tables are read, the message is given on the final line
The hash of the message
- You will never get two occurrences of one symbol in the same table
- Time limit: 1 second
- Memory limit: 16 MB
Input: | Output: |
---|---|
a -> 1 b -> 2 STOP ! -> q @ -> w END 1 -> ! 2 -> @ HALT ababaaababbbababababbabababaaabababbababababbababbbbbbabbabaaaaaa |
q2!2!1q2!2@2q2!2!2q2@1@1w1@1!1w1@1@2q2!2!2q2@1@1w2@2@2q2@1@1q1!1! |