Skip to content

Instantly share code, notes, and snippets.

@Ro6afF

Ro6afF/task2.md Secret

Last active September 10, 2017 06:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ro6afF/2c89e910cd5be0f435b15fcb381da31b to your computer and use it in GitHub Desktop.
Save Ro6afF/2c89e910cd5be0f435b15fcb381da31b to your computer and use it in GitHub Desktop.

Dimitri the Cryptographer

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:
    1. Every original symbol (ex. examplestring) is replaced with the corresponding one from the first table
    2. After that, every second symbol (ex. examplestring) is replaced with the corresponding one from the second table
    3. Then every third symbol (ex. examplestring) is replaced with the corresponding one from the third table
    4. If the symbol is not in the table, which you are currently working with, continue to the next table.

Input:

  • 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 or HALT).
  • After all the tables are read, the message is given on the final line

Output:

The hash of the message

Constraints:

  • You will never get two occurrences of one symbol in the same table
  • Time limit: 1 second
  • Memory limit: 16 MB

Examples:

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!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment