Hangzhou Electric 2031 Binary conversion

Source: Internet
Author: User

Problem description Enter a decimal number n to convert it to the R-binary output.

Input data contains multiple test instances, each containing two integer n (32-bit integers) and R (2<=r<=16, r<>10).

Output outputs the converted number for each test instance, with one row for each output. If R is greater than 10, then the corresponding number rules refer to 16 binary (for example, 10 is represented by a, and so on).

Sample Input7 2 23 12-4 3

Sample Output111 1b-11
1#include <stdio.h>2#include <string.h>3#include <cmath>4 inta[ +];5 intMain ()6 {7     intN, R, K;8      while(~SCANF ("%d%d", &n, &R))9     {TenK =0; One         //memset (A, 0, sizeof (a)); A         if(R > -|| R <2|| R = =Ten) -             Continue; -         if(N <0) printf ("-"); the          while(N) -         { -a[k++] = ABS (N%R); -N = ABS (n/R); +         } -         if(R <Ten) +         { A              for(intj = k1; J >=0; j--) atprintf"%d", A[j]); -         } -         Else -         { -              for(intj = k-1; J >=0; j--) -printf"%x", A[j]);//output in hexadecimal in         } -printf"\ n"); to     } +     return 0; -}

Hangzhou Electric 2031 Binary conversion

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.