1 条题解

  • 0
    @ 2026-11-05 19:18:24

    依旧字符串+模拟,顶多普及-难度。
    思路是从字符串s中读取里面的数字,然后按照题目给的运算,最后比较其正确性即可。
    需要注意的是,输入最后一位有 X 的可能,需要特判。
    以下是AC代码:

    #include <bits/stdc++.h>
    using namespace std;
    string s;
    int a[9], j = 1, ans;
    int main(){
        cin >> s;
        for(int i = 0; i <= 12; i++){
            if(i == 0){
                ans += (s[i] - '0') * j;
                j++;
            }
            if(i >= 2 && i <= 4){
                ans += (s[i] - '0') * j;
                j++;
            }
            if(i >= 6 && i <= 10){
                ans += (s[i] - '0') * j;
                j++;
            }
        }
        ans = ans % 11;
        if(ans == 10 && s[12] == 'X'){
            cout << "Right" << endl;
        }
        else if(ans == s[12] - '0'){
            cout << "Right" << endl;
        }
        else if(ans == 10 && s[12] != 'X'){
            s[12] = 'X';
            cout << s << endl;
        }
        else{
            s[12] = char('0' + ans);
            cout << s << endl;
        }
        return 0;
    }
    
    
  • 1

信息

ID
1005
难度
9
分类
字符串 点击显示
标签
递交数
6
已通过
3
通过率
50%
上传者