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.