HUD 2031: hexadecimal conversion

Source: Internet
Author: User

Hexadecimal conversion Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 23830 accepted submission (s): 13344


Problem description input a decimal number N and convert it to the r hexadecimal number output.
Input data contains multiple test instances. Each test instance contains two integers, n (32-bit integer) and R (2 <= r <= 16, r <> 10 ).
 
Output is the number of converted outputs for each test instance. Each output occupies one row. If the R value is greater than 10, the corresponding digital rule is in hexadecimal notation (for example, 10 is represented by a, and so on ).
Sample Input
7 223 12-4 3
 
Sample output
1111B-11

Question ..


#include<cstdio>#include<cstring>#include<algorithm>#include<iostream>using namespace std;int main(){    int n, m, s, i;    char c, a[1000];    while(scanf("%d%d",&n,&m)!=EOF)    {        i=0;        if(n<0)            printf("-");        while(n)        {            s=abs(n%m);            if(s>=0 && s<=9 || s<0 && s>=-9)            a[i]='0'+s;            if(s>9)            {                c='A'+s-10;                a[i]=c;            }            n=n/m;            i++;        }        for(int j=i-1; j>=0; j--)            printf("%c", a[j]);        printf("\n");    }    return 0;}



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.