• 使用algorithm的revers函数反转string 字符串
#include <string>
#include<algorithm>
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 ans;
    while(n)
    {
        int m = n%16;
        if(m<10)
            ans.push_back(char('0'+m));
        else 
            ans.push_back(char('A' + m-10));
        n/=16;
    }
    reverse(ans.begin(), ans.end());//反转字符串
    return ans;
}