问题描述
给定n个十六进制正整数,输出它们对应的八进制数。
输入格式
输入的第一行为一个正整数n (1<=n<=10)。
接下来n行,每行一个由0~9、大写字母A~F组成的字符串,表示要转换的十六进制正整数,每个十六进制数长度不超过100000。
输出格式
输出n行,每行为输入对应的八进制正整数。
注意
输入的十六进制数不会有前导0,比如012A。
输出的八进制数也不能有前导0。
样例输入
2
39
123ABC
样例输出
71
4435274
提示
先将十六进制数转换成某进制数,再由某进制数转换成八进制。
Simple method: convert hexadecimal to binary and then to octal
You can convert hexadecimal to binary first
123ABC -> 0001 0010 0011 1010 1011 1100
Then look at the binary sequence in groups of three (from the lowest bit)
0001 0010 0011 1010 1011 1100 -> 000 100 100 011 101 010 111 100
Then convert the binary sequence of three groups into octal
000 100 100 011 101 010 111 100 -> 04435274
Just discard the highest zero
Binary has a corresponding relationship with hexadecimal and octal
ps I think this level of problems should not appear in this community.