Submit | All submissions | Best solutions | Back to list |
GCJ1C09A - All Your Base |
In A.D. 2100, aliens came to Earth. They wrote a message in a cryptic language, and next to it they wrote a series of symbols. We've come to the conclusion that the symbols indicate a number: the number of seconds before war begins!
Unfortunately we have no idea what each symbol means. We've decided that each symbol indicates one digit, but we aren't sure what each digit means or what base the aliens are using. For example, if they wrote "ab2ac999", they could have meant "31536000" in base 10 -- exactly one year -- or they could have meant "12314555" in base 6 -- 398951 seconds, or about four and a half days. We are sure of three things: the number is positive; like us, the aliens will never start a number with a zero; and they aren't using unary (base 1).
Your job is to determine the minimum possible number of seconds before war begins.
Input
The first line of input contains a single integer, T. T test cases follow. Each test case is a string on a line by itself. The line will contain only characters in the 'a' to 'z' and '0' to '9' ranges (with no spaces and no punctuation), representing the message the aliens left us. The test cases are independent, and can be in different bases with the symbols meaning different things.
Output
For each test case, output a line in the following format:
Case #X: V
Where X is the case number (starting from 1) and V is the minimum number of seconds before war begins.
Limits
1 ≤ T ≤ 100
1 ≤ the length of each line < 61
The answer will never exceed 1018
Sample
Input 3 11001001 cats zig Output Case #1: 201 Case #2: 75 Case #3: 11
Added by: | Shafaet |
Date: | 2013-05-07 |
Time limit: | 20s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 |
Resource: | Google Codejam 2009, Round 1C, Problem A |
hide comments
|
|||||
2013-10-29 14:00:04 Martijn Muijsers
Oh dear... that is just SO incredibly evil. Getting this question right depends on reading the description VEEERY carefully. Damn you problem setter, you almost got me! Great prob :) |
|||||
2013-10-25 08:50:19 Aditya Pande
This kind of output format has cost me so many WA's Why not just print the number.... why? |
|||||
2013-08-25 18:09:11 metalbird
getting correct output for every input, still WA....! suggest any special test cases... |
|||||
2013-06-28 05:11:32 apsdehal
the question and its conditions should be carefully read Caused 4 WA's |
|||||
2013-06-08 10:28:28 raunakrocks
AC!! after many WA!!huh :P |
|||||
2013-05-19 15:27:51 (Tjandra Satria Gunawan)(曾毅昆)
"We are sure of three things: the number is positive;" Because I didn't read problem description carefully, I got 1 WA.. finally got AC :-) |
|||||
2013-05-14 05:31:43 fitcat
Shafaet: The output of my program passed when submitted to the official site but got WA here. Would you please give me a hint? My submission id is 9258249. Edit: Never mind. My stupid mistake. Last edit: 2013-05-14 07:54:35 |