Base Conversion
InterviewTime limit1sMemory limit128 MB
Convert a number given in an arbitrary base (2 to 36, using letters for digits above 9) into its decimal value.
- Level
Easy2 of 10
- Topics
- Math, Implementation, String
- Solved
- No attempts yet
Problem
You are given a number N written in base B. Write a program that converts N to decimal and prints the result.
In bases greater than 10, a single digit can have a value greater than 9. Values from 10 through 35 are represented by uppercase letters A through Z.
A: 10, B: 11, ..., F: 15, ..., Y: 34, Z: 35
Input
The first line contains the base-B number N and the base B, separated by a space. (2 <= B <= 36)
The decimal value of N is always at most 1,000,000,000.
Output
Print the decimal value of N on the first line.