3 条题解

  • 0
    @ 2024-6-5 0:17:48

    解析:找出每个字符串中最大的字符,根据其大小判断可能是几进制数,详见代码:

    #include <iostream>
    using namespace std;
    int main() {
        int n = 0;
        cin >> n;
        for (int i = 0; i < n; i++) {
            string s;
            cin >> s;
            char maxc = '0';
            for (int i = 0; i<s.length(); i++)
                if (s[i] > maxc)
                    maxc = s[i];
            if (maxc>'F'){
                cout<<"0 0 0 0"<<endl;
            }else if(maxc>'9'){
                cout<<"0 0 0 1"<<endl;
            }else if (maxc>'7'){
                cout<<"0 0 1 1"<<endl;
            }else if (maxc>'1'){
                cout<<"0 1 1 1"<<endl;
            }else{
                cout<<"1 1 1 1"<<endl;
            }
        }
        return 0;
    }
    

    另一种解法:

    #include <iostream>
    using namespace std;
    int main() {
        int n = 0;
        cin >> n;
        for (int i = 0; i < n; i++) {
            char str[11];
            cin >> str;
            char max = '0';
            for (int i = 0; str[i] != '\0'; i++)
                if (str[i] > max)
                    max = str[i];
            cout << (max <= '1') << " " << (max <= '7') << " " << (max <= '9') << " " <<
                 (max <= 'F') << endl;
        }
        return 0;
    }
    

    信息

    ID
    1298
    时间
    1000ms
    内存
    256MiB
    难度
    10
    标签
    递交数
    7
    已通过
    2
    上传者