CSU 1160 (binary issue)

Source: Internet
Author: User
Tags uppercase letter

CSU 1160Time limit:1000MS Memory Limit:131072KB 64bit IO Format:%lld &%llu

Description

Converts a decimal integer to 16, in the form of 0x, 10~15 is represented by an uppercase letter, a~f.

Input

One integer per line x,0<= x <= 2^31.

Output

Each row outputs a corresponding eight-bit hexadecimal integer, including the leading 0.

Sample Input

01023

Sample Output

0x000000000x000003ff


This question is very ingenious, there are many solutions, here is what I wrote at the game:

#include<stdio.h>IntMain(){int aB, I;Char Hex[8];While(scanf("%d", &a)!=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;< Span class= "Sh-cbracket" > 


But there's actually a simpler format output

#include <stdio.h>
int main ()
{
 int x;
while (scanf ("%d", &x)!=eof)
{
printf ("0x%.8x\n", x);
}
return 0;
}

< Span class= "Sh-symbol" > < Span class= "sh-string" > After reading is not want to vomit blood, haha.  

CSU 1160 (binary issue)

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.