#P1603. Decrypt Snowden's Clue
Decrypt Snowden's Clue
Decrypt Snowden's Clue
In 2013, a mysterious English note was found on Snowden's airplane seat: "Obama is a two five zero." Although its wording appears random, it hides the key to a cryptographic password. As an officer, you have to decipher the password before time runs out.
The password is derived from the sentence by following these steps:
- Extract all words that represent numbers (in English) whose values are at most 20. There are two groups of valid words:
- Regular: one, two, three, four, five, six, seven, eight, nine, ten, eleven, twelve, thirteen, fourteen, fifteen, sixteen, seventeen, eighteen, nineteen, twenty, and (additionally) zero.
- Non‐regular: a, both, another, first, second, third. (Note: For ambiguity, treat "another" as 1.) Also, treat "a" as 1, "both" as 2, "first" as 1, "second" as 2, and "third" as 3.
- For each extracted number v, compute its square modulo 100, i.e. \(v^2 \bmod 100\). Represent the result as a two‐digit number (using a leading zero if necessary). For example, if \(v=5\) then \(5^2=25\) becomes "25", and if \(v=2\) then \(2^2=4\) becomes "04".
- Now, imagine that each two‐digit result is a block. In one arrangement, place the blocks in a row to form a new number. If the concatenated result starts with one or more zeros, remove all leading zeros.
- Among all possible permutations (reorderings) of these blocks, find the one that forms the smallest numerical value. That number is the required password.
Example:
Input: "Obama is a two five zero."
- Extracted numbers: a \(\to\) 1, two \(\to\) 2, five \(\to\) 5, zero \(\to\) 0.
- Squares modulo 100: 12 \(\to\) 01, 22 \(\to\) 04, 52 \(\to\) 25, 02 \(\to\) 00.
- Finding the permutation that gives the smallest number: The optimal order is "00", "01", "04", "25" resulting in "00010425" which becomes "10425" after removing leading zeros.
- Password: 10425
Your task is to implement the procedure described above. The input is a single line containing the sentence. The output is the smallest possible password as explained.
inputFormat
The input contains a single line with a sentence of text (possibly containing punctuation). The sentence will include some valid English words representing numbers as described above.
outputFormat
Output the smallest password (as a number string with no leading zeros) obtained by processing the sentence.
sample
Obama is a two five zero.
10425