Conversion, Hangzhou Electric 0j-2031 original title address: http://acm.hdu.edu.cn/showproblem.php?pid=2031
"Problem Description" Enter a decimal number n and convert it to the R-binary output. The input data for "input" 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 Input" 7 2 23 12-4 3 "Sample Output" 111 1b-11 "AC Code"
1#include <stdio.h>2 voidPrintintnum)3 {4 if(num = =Ten) printf ("%c",'A');5 Else if(num = = One) printf ("%c",'B');6 Else if(num = = A) printf ("%c",'C');7 Else if(num = = -) printf ("%c",'D');8 Else if(num = = -) printf ("%c",'E');9 Else if(num = = the) printf ("%c",'F');Ten Elseprintf"%d", num); One } A Main () - { - intA, B, I, j, flag =0; the intc[ -]; - while(~SCANF ("%d%d", &a, &b)) - { - inti =0; + if(b<2|| B> -|| b==Ten) Break; - if(a<0) A =-A, flag =1; + while(a) A { atC[i] = a%b; -A = A/b; -i++; - } - if(flag) printf ("-"), flag =0; - for(j=i-1; j>=0; j--) in print (c[j]); -printf"\ n"); to } +}
In-process conversion, Hangzhou electric 0j-2031