1 条题解

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

    C++ :

    #include <iostream>
    using namespace std;
    string octalToBinary(char octalDigit) {
        switch (octalDigit) {
            case '0': return "000";
            case '1': return "001";
            case '2': return "010";
            case '3': return "011";
            case '4': return "100";
            case '5': return "101";
            case '6': return "110";
            case '7': return "111";
            default: return "";
        }
    }
    void convertOctalToBinary(string octal) {
        string binary = "";
        for (char digit : octal) {
            binary += octalToBinary(digit);
        }
        // 去除多余的前导零
        int start = 0;
        while (start < binary.length() && binary[start] == '0') {
            start++;
        }
        if (start == binary.length()) {
            cout << "0" << endl;  // 特殊情况,输入为 0 时
        } else {
            cout << binary.substr(start) << endl;
        }
    }
    int main() {
        string octal;
        cin >> octal;
        convertOctalToBinary(octal);
        return 0;
    }
    
    • 1

    信息

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