#include <iostream>
#include <string>
using namespace std;
string toHexString(int n);
int main() {
int n;
cin >> n;
string hexStr = toHexString(n);
cout << hexStr << endl;
return 0;
}
string toHexString(int n) {
//定义字符串变量,用于记录最终结果
string res="";
while(n!=0){
//计算当前对16取余的结果
int mod=n%16;
//如果是0-9,则对应字符'0'-'9'
if(mod>=0&&mod<=9){
char c=mod+'0';
//将字符加在res前面
res=c+res;
}
//如果是10-15,则对应字符'A'-'F'
else{
char c=mod-10+'A';
//将字符加在res前面
res=c+res;
}
n=n/16;
}
return res;
}

京公网安备 11010502036488号