시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
20 초 (추가 시간 없음) | 1024 MB | 22 | 13 | 12 | 80.000% |
Susie and Calvin are classmates. Calvin would like to be able to pass notes to Susie in class without their teacher or other classmates knowing what they are talking about, just in case the notes fall into the wrong hands. Calvin has devised the a system to encrypt his messages.
Calvin only passes one word to Susie each time, and that word consists of only uppercase letters, because Calvin is so excited to talk to Susie. Each word is encrypted as follows:
A
= 0, B
= 1, ..., Z
= 25.Let's take a look at one of the notes Calvin is writing for Susie. Since Calvin is always hungry, he wants to let Susie know that he wants to eat again. Calvin encrypts the word SOUP
as follows:
S
= 18, O
= 14, U
= 20, and P
= 15.OMDU
, and this is the encrypted word that Calvin will write on the note for Susie.It is guaranteed that Calvin will not send Susie any words that cannot be decrypted at all. For example, Calvin would not send Susie the word APE
, since it does not have any valid decryptions. (That is, there is no word that Calvin could have encrypted to APE
.)
However, Calvin's system is not perfect, and some of the words he sends Susie can actually be decrypted to multiple words, creating ambiguity! For example, BCB
can be decrypted to ABC
or CBA
, among other possibilities.
Susie pulled another all-nighter yesterday to finish school projects, and she is too tired to decrypt Calvin's messages. She needs your help!
The first line of the input gives the number of test cases, T. T test cases follow. Each case is a single line that contains a string W of uppercase letters: an encrypted word that Calvin has sent.
For each test case, output one line containing Case #x: y
, where x
is the test case number (starting from 1) and y
is the decrypted word, or AMBIGUOUS
if it is impossible to uniquely determine the decrypted word.
AMBIGUOUS
. (You will only output that when the decryption is ambiguous.)3 OMDU BCB AOAAAN
Case #1: SOUP Case #2: AMBIGUOUS Case #3: BANANA
Note that the last sample case would not appear in the Small dataset.
Sample Cases #1 & #2 were explained in the problem statement.
In Sample Case #3, BANANA
is the only word that encrypts to AOAAAN
.
Contest > Google > Kick Start > Google Kick Start 2017 > Round C A번