好像是计算出错,但没看出来
查看原帖
好像是计算出错,但没看出来
1212315
codecolorThD楼主2024/1/22 21:41

代码如下,只有1,4,7,过了,没过的都是最后一位输出错误。

#include <iostream>
#include <string>
using namespace std;

int main() {
    string str;
    int all = 0,j = 0;
    cin >> str;
    for (int i = 0; i <= 11; i++) {
        if (str[i] != '-') {
            j++;
            all += int(str[i] - '0') * j;
        }
    }
    all %= 11;
    if (all == (str[12] - '0')||(all == 10 && str[12] == 'X'))
        cout << "Right";
    else if( all == 10)
        cout << str << '\b' << 'X';
    else
        cout << str << '\b' << all;
    return 0;
}
2024/1/22 21:41
加载中...