What base is this?
InterviewTime limit2sMemory limit512 MB
For each digit string, print its value read as octal, decimal, and hexadecimal; if it has an 8 or 9, print 0 for the octal value.
- Level
Easy3 of 10
- Topics
- Implementation, Math, String, Brute force
- Solved
- No attempts yet
Problem
Languages such as C, C++, and Java let you write a constant in several bases by putting a prefix character in front of it.
An octal constant starts with the digit 0, a hexadecimal constant starts with 0x, and a decimal constant takes no prefix. Written that way, the decimal number 4660 looks like this.
- octal: 011064
- decimal: 4660
- hexadecimal: 0x1234
Without the prefix a compiler has no way to tell which base was meant. Drop the 0x from 0x1234 and the compiler may read the digits as octal or as decimal, even though the person who typed them meant hexadecimal.
Assume that mistake has happened. Given strings made only of the digits 0 through 9, read each string as an octal number, as a decimal number, and as a hexadecimal number.
Input
The first line contains the number of test data T (1 ≤ T ≤ 10000).
Each of the next T lines contains an integer K, the number of that test data, and a string, separated by a space. The string consists only of the digits 0 through 9, its length is between 1 and 7, and it may start with 0.
Output
For each test data print one line holding K, then the value of the string read as an octal number, as a decimal number, and as a hexadecimal number, in that order and separated by spaces. Write all three values in decimal.
If the string contains an 8 or a 9 it cannot be read as an octal number, so print 0 in place of the octal value.