1 条题解

  • 0
    @ 2025-11-30 16:24:20

    C++ :

    #include <iostream>
    using namespace std;
    
    void decimalToHex(int n) {
        char hex[100];
        int i = 0;
        
        if (n == 0) {
            cout << "0" << endl;
            return;
        }
        
        while (n > 0) {
            int remainder = n % 16;
            if (remainder < 10)
                hex[i++] = remainder + '0';  // 0-9
            else
                hex[i++] = remainder - 10 + 'A';  // A-F
            n /= 16;
        }
    
        // 输出十六进制时需要逆序
        for (int j = i - 1; j >= 0; j--) {
            cout << hex[j];
        }
        cout << endl;
    }
    
    int main() {
        int n;
        cin >> n;
        decimalToHex(n);
        return 0;
    }
    
    
    • 1

    信息

    ID
    577
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者