题解 | #十进制整数转十六进制字符串#
十进制整数转十六进制字符串
https://www.nowcoder.com/practice/80eca5f47e6f473893151b863b25aba1
#include <iostream> #include <string> #include <vector> 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) { // write your code here...... string s = ""; string s1 = "0123456789ABCDEF"; while (n != 0) { int num = n % 16; s = s + s1[num] ; n = n / 16; } string s2; for (int i = s.length() - 1; i >= 0; i--) { s2.push_back(s[i]); } return s2; }