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)