1292: Hex Turn octal time limit: 1 Sec memory limit: MB
Submissions: 1 Resolution: 1
Submitted State [Discussion Version] [Edit] Title Description
Given n hexadecimal positive integers, output their corresponding octal numbers.
Input
The first behavior of the input is a positive integer n (1<=n<=10). Next n rows, each line a string of 0~9, uppercase letters A~F, representing the hexadecimal positive integer to be converted, each hexadecimal number is not more than 100000.
Output
Outputs n rows, each of which enters a corresponding octal positive integer.
Sample input2 123ABCSample output4435274Tips
The hexadecimal number entered does not have a leading 0, such as 012A.
The octal number of the output cannot have a leading 0.
16 binary three bits corresponding to octal four-bit
#include <stdio.h> #include <string.h> #define MAXN 400010char BUF[MAXN], str[maxn];int arr[] = {1, +, 256};in T Main () {//Freopen ("Stdin.txt", "R", stdin);//Freopen ("Stdout.txt", "w", stdout); int n, I, J, K, Len, TMP, ID;SCANF ("%d ", &n), while (n--) {scanf ("%s ", buf); len = strlen (BUF); for (i = len-1, id = 0; I >= 0; I-= 3) {for (j = tmp = 0; J < 3 && i-j >= 0; ++j) {if (Buf[i-j] >= ' A ') {TMP = TMP + (buf[i-j]-' A ' + (Ten) * arr[j];} else {TMP = TMP + (buf[i-j]-' 0 ') * arr[j];}} for (k = 0; k < 4; ++k) {str[id++] = tmp% 8;tmp/= 8;}} while (!str[--id]), for (; ID >= 0;--id) printf ("%d", Str[id]);p utchar (' \ n ');} return 0;}
HPUOJ1292 Hex goto Octal