Number Base Conversion
InterviewTime limit1sMemory limit128 MB
Convert a number given in one base to another base, where digits run 0-9, A-Z, a-z, and print a blank line after each conversion.
- Level
Medium4 of 10
- Topics
- Math, String, Implementation, Simulation
- Solved
- No attempts yet
Problem
Write a program that converts a number written in one base into the same number written in another base. There are 62 possible digits:
{ 0-9, A-Z, a-z }
Hint: if you chain base conversions, feeding the output of one conversion in as the input to the next, then when you return to the original base you should recover the original number.
Input
The first line contains a single positive integer: the number of lines that follow.
Each following line contains a (decimal) input base, a (decimal) output base, and a number written in the input base, separated by spaces. Both the input base and the output base are in the range from 2 to 62.
The digit values are: 0–9 have their usual meanings 0 through 9, and A = 10, B = 11, …, Z = 35, a = 36, b = 37, …, z = 61.
Output
For each base conversion, print three lines.
- The first line is the input base (in decimal), a space, then the input number exactly as it was given.
- The second line is the output base (in decimal), a space, then the same number expressed in the output base.
- The third line is blank.