CSU 1160 (hexadecimal problem), csu1160 hexadecimal Problem

Source: Internet
Author: User

CSU 1160 (hexadecimal problem), csu1160 hexadecimal Problem
CSU 1160Time Limit:1000 MSMemory Limit:131072KB64bit IO Format:% Lld & % llu

Description

Converts a decimal integer to a hexadecimal value. The format starts with 0x and ranges from 10 to 10 ~ 15 uppercase letters ~ F.

Input

Each row has an integer x, 0 <=x <= 2 ^ 31.

Output

The eight-digit hexadecimal integer corresponding to the output of each row, including the leading 0.

Sample Input

01023

Sample Output

0x000000000x000003FF


This is a clever question. There are multiple solutions. The following is what I wrote during the competition:

# Include <stdio. h> int main () {int a, B, I; char hex [8]; while (scanf ("% d", & )! = EOF) {for (I = 0; I <8; I ++) hex [I] = '0'; I = 0; while (a> = 16) {B = a % 16; if (B <10) hex [I] = B + '0'; else hex [I] = B-10 + 'a '; a/= 16; I ++;} if (a <10) hex [I] = a + '0'; elsehex [I] = A-10 + 'a '; printf ("0x"); for (I = 7; I> = 0; I --) printf ("% c", hex [I]); printf ("\ n");} return 0 ;}


But there is actually a simpler format output.

# Include <stdio. h>
Int main ()
{
Int x;
While (scanf ("% d", & x )! = EOF)
{
Printf ("0x %. 8X \ n", x );
}
Return 0;
}

Do you want to vomit blood after reading it? haha.

Related Article

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.