80分,各位dalao帮个忙吧

P1055 [NOIP2008 普及组] ISBN 号码

鲁锦聪 @ 2021-07-19 13:38:19

#include <bits/stdc++.h>
using namespace std;
int a1[10],s;
char a[10],b,c;
int main(){
    cin >> a[1] >> b >> a[2] >> a[3] >> a[4] >> b >> a[5] >> a[6] >> a[7] >> a[8] >> a[9] >> b >> c;
    for(int i = 1;i <= 9;i++){
        a1[i] = (int)(a[i] - '0');
        s += a1[i] * i;
    }
    s %= 11;
    if(s == (int)(c - '0'))
        cout << "Right";
    else{
        if(s == 10)
            cout << a1[1] << "-" << a1[2] << a1[3] << a1[4] << "-" << a1[5] << a1[6] << a1[7] << a1[8] << a1[9] << "-X";
        else
            cout << a1[1] << "-" << a1[2] << a1[3] << a1[4] << "-" << a1[5] << a1[6] << a1[7] << a1[8] << a1[9] << "-" << s;
    }
    return 0;

}

by 阿丑 @ 2021-07-19 14:02:17

@鲁锦聪

在判断的时候没有考虑 c=='X' 的情况


by zry20100305 @ 2021-07-19 14:12:05

@鲁锦聪 少算了一种情况


by 鲁锦聪 @ 2021-07-19 17:58:12

@阿丑 谢谢


by 鲁锦聪 @ 2021-07-19 17:58:25

@zry20100305 谢谢


|