This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
#include <bits/stdc++.h>
using namespace std;
//函数:十进制转任意进制
string tenToR(int n, int r) {
if (n == 0) return "0";
//十进制n转r进制 ,返回字符串s
string str = "";
stack<int> s;
while (n) {
s.push(n % r);
n = n / r;
}
while (!s.empty()) {
switch (s.top()) {
case 10:
str += 'A';
break;
case 11:
str += 'B';
case 12:
str += 'C';
case 13:
str += 'D';
case 14:
str += 'E';
case 15:
str += 'F';
default:
str += s.top() + '0';
s.pop();
return str;
int main() {
int n;
cin >> n;
cout << tenToR(n,16) << endl;
return 0;