Data Structure & Algorithm: Level-1 Problem #6. Convert Base N

Given a decimal number and a base N (which is between 2 and 35), convert the decimal number to the base-N number. For base more than 9, use uppercase letter A-Z to represent 10 to 35.

Sample Input:

2021 17

Sample Output:

6GF

With the above sample, the base-17 number for decimal number 2021 is 6GF.


数据结构和算法:初级练习题 #6 – 数字转换进制


给定一个十进制数字和进制N(N的范围介于2和35之间),把该十进制数字转换为N进制数字。如果进制大于9,用大写字母A-Z代表数字10-35。

输入样例:

2021 17

输出样例:

6GF

在上面的输入样例中,十进制数字2021转换成17进制的数字是6GF。


Python Solution

Convert Base N