HPUOJ1292 Hex goto Octal

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.