题解 | #十进制整数转十六进制字符串#

十进制整数转十六进制字符串

https://www.nowcoder.com/practice/80eca5f47e6f473893151b863b25aba1

#include <cctype>
#include <ios>
#include <iostream>
#include <sstream>
#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......
    ostringstream os;
    os << hex << n;

    string s {os.str()};
    transform(s.begin(), s.end(), s.begin(), ::toupper);

    return s;
}

全部评论

相关推荐

祈求顺利毕业😁:简历很好了,多投吧牛油😂。主要是环境不好,大家也卷
点赞 评论 收藏
转发
点赞 评论 收藏
转发
点赞 收藏 评论
分享
牛客网
牛客企业服务