2031 HDOJ hex conversion

Problem Description
Enter a decimal number N, it converts into R decimal output.
 
Input
Input data comprising a plurality of test cases, each test case contains two integers N (32-bit integer) and R (2 <= R <= 16, R <> 10).
 
Output
After each test the number of examples of output converter, each output per line. If rule number R is greater than 10, then the corresponding hexadecimal reference (for example, represented by 10 A, etc.).
 

Sample Input
7 2
23 12
-4 3
 

Sample Output
111
1B
-11
 
Reference code is as follows: Note that comments are marked.
 
     

/ * Decimal conversion * /

 
     

#include <the iostream>
#include <algorithm>
#include <String>
the using namespace STD;
int main ()
{
int N, R & lt;
String A ( "0123456789ABCDEFG"); // coup
while (cin >> N >> R) // enter the number N, to be converted to hexadecimal R & lt
{
String S = "";
BOOL = in Flag to true;
IF (N <0) // If N is negative, the process
{
in Flag to false =;
N = -N;
}
IF (N == 0)
COUT 0 << << endl;
the while (N> 0)
{
S = S + A [N R & lt%];
N / = R & lt;
}

Reverse (s.begin (), S. end ()); // the reverse s
IF (In Flag)!
{
s = "-" + s;
}
COUT s << << endl;
}
return 0;
}

 

 

This is just decimal to hexadecimal other issues, we need to do more comprehensive follow-up perfect.

00:14:3800:14:432019-09-16

Guess you like

Origin www.cnblogs.com/ManbaDF99/p/11525225.html