Basic practice decimal to hexadecimal time limit: 1.0s memory limit: 512.0MBThe problem description hexadecimal number is a representation of an integer that is often used in programming. It has 0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f a total of 16 symbols, representing 0 to 15 of the decimal number. The hexadecimal count method is 16 in 1, so the decimal number 16 in hexadecimal is 10, while the decimal 17 in hexadecimal is 11, and so on, the decimal 30 in hexadecimal is 1 E.
A nonnegative integer is given, which is represented as a 16-binary form. Input format input contains a non-negative integer A that represents the number to convert. 0<=a<=2147483647 output Format Output 16 binary representation of this integer example input 30 sample output 1E
#include <stdio.h> #include <string.h> #include <string> #include <math.h> #include < Algorithm> #define LL Long long#define PI atan (1.0) *4#define DD doublea#define MAX 100100#define mod 10007using Namespac E std;int s[100];char p[]= "ABCDEF"; int op[]={10,11,12,13,14,15};int main () { int j,i,len,sum,k; LL n,m; while (scanf ("%lld", &n)!=eof) { if (n==0) { printf ("0\n"); Continue; } k=0; while (n) { s[k++]=n%16; n/=16; } for (i=k-1;i>=0;i--) { if (s[i]<10) printf ("%d", s[i]); else { for (j=0;j<6;j++) { if (s[i]==op[j]) printf ("%c", P[j]); }} printf ("\ n");
Blue Bridge Cup Basics practice decimal to Hex