#include<iostream>
#include<string>
#include<algorithm>
#include<iterator>
using namespace std;
string numToString(int r)
{
if (r >= 10 && r <= 15)
{
string ans;
switch (r)
{
case 10:
ans = 'A';
break;
case 11:
ans = 'B';
break;
case 12:
ans = 'C';
break;
case 13:
ans = 'D';
break;
case 14:
ans = 'E';
break;
case 15:
ans = 'F';
break;
default:
break;
}
return ans;
}
char ch[2];
itoa(r,ch,10);//C11才开始支持to_string
return ch;
}
void tenToSixteen(string str)// 14 D
{
int sum = atoi(str.c_str());
//十进制转十六进制 215 13.7 0.13
string sum2 = "";//保存结果
do{
sum2.append(numToString(sum % 16));//保存余数
sum /= 16;//保存得数
} while (sum != 0);//得数不位0
reverse(sum2.begin(), sum2.end());//反转
for (size_t i = 0; i < sum2.length(); i++)
{
cout << sum2[i];
}
cout << endl;
}
int main()
{
string s;//接收第一行(有几个要转换的字符串)
getline(cin, s);
tenToSixteen(s);
return 0;
}
11-05
764