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