1 #include<bits/stdc++.h> 2 using namespace std; 3 int main() { 4 int n; 5 cin >> n; 6 vector<int> v; 7 if (n == 0) { 8 cout << 0 << endl; 9 return 0; 10 } 11 while (n != 0) { 12 int t = n % 16; 13 v.push_back(t); 14 n /= 16; 15 } 16 for (int i = v.size() - 1; i >= 0; i--) { 17 if (v[i] < 10) { 18 cout << v[i]; 19 } else { 20 cout << char(‘A‘ + v[i] - 10); 21 } 22 } 23 return 0; 24 }
原文:https://www.cnblogs.com/fx1998/p/12807019.html