Blue Bridge Cup Basics practice decimal to Hex

Source: Internet
Author: User
Tags decimal to hex

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

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.