Copyright: qq836678589 https://blog.csdn.net/weixin_43924623/article/details/90521512
Hexadecimal conversion
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 73111 Accepted Submission(s): 39670
Problem Description
input 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
number after each test case conversion output, 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
#include<iostream>
using namespace std;
int main(){
int n,r,num[100],i;
bool a;
while(cin>>n>>r){
i=0;
a=false;
if(n<0){
a=true;
n=-n;
}
while(n){
num[i++]=n%r;
n=n/r;
}
if(a){
cout<<"-";
}
for(int j=i-1;j>=0;j--){
if(num[j]<10)
cout<<num[j];
else
printf("%c",num[j]+55);
}
cout<<endl;
}
return 0;
}