牛客假日团队赛21 E.Hexadecimal Conversion

牛客假日团队赛21 E.Hexadecimal Conversion

题目描述

Bessie was teaching Jessie, her protege interesting in programming contests the binary facts of life. She explained that computers work in binary (base 2) and that all computer numbers in general are stored as 0’s and 1’s. Jessie was a bit unclear on the concept, so Bessie made her an exercise, shown below.
Write a program that converts an unsigned hexadecimal number to octal (base 8) form. Hexadecimal number can have at most 100,000 digits and is composed of digits and capital letters from A to F.
Note: a hexadecimal number is a special way of representing numbers in base 16. The digits 0-9 still correspond to 0-9, and then A (capital A!) corresponds to 10, B to 11, etc. (F stands for 15).
Hint: there is an easier way to convert from hexadecimal to octal than by converting hexadecimal -> decimal -> octal. It might help to think about the numbers in binary (base 2).

输入描述:

Line 1: A single hexadecimal number. Multidigit numbers will have no leading zeroes (i.e., A1 instead of 00A1). 0 (by itself) is a valid input.

输出描述:

Line 1: The octal value with no leading zeros. If the input is 0, the output should also be 0.

输入

123ABC

输出

4435274

这题看到很多人写挂,用python秒过,嘻嘻(●’◡’●)

s=input()
n=int(s,16)
print(oct(n)[2:])

你可能感兴趣的:(牛客,进制转换)