70分求助!!!大佬们帮忙看看

P1055 [NOIP2008 普及组] ISBN 号码

KAchor @ 2022-01-04 11:42:34

#include<iostream>
#include<cstring>
#include<stdio.h>

using namespace std;

void judge(char a[14])
{
    int sum = 0, n, k = 1;
    char m;
    for (int i = 0; i < 11; i++)
    {
        if (a[i] != '-')
        {       
            sum += (a[i] - '0') * k;
            k++;
        }
    }
    n = sum % 11;
    m = n + '0';
    if (m == a[12]) cout << "Right";
    else if (n == 10 && a[12] == 'X') cout << "Right";
    else
    {
        cout << a;
    }
}

int main()
{
    char ISBN[14];
    cin >> ISBN; 
    judge(ISBN);
}

by Ascetic @ 2022-01-06 14:20:35

 if (m == a[12])
        cout << "Right";
    else if (n == 10 && a[12] == 'X') 
        cout << "Right";
    else
    {
        if (n == 10)
            a[12] = 'X';
        else
            a[12] = m;
        cout << a;
    }

这样改正一下就好了,你忽略了取余10的情况下改正并输出带有X的正确识别码的情况。试试测试6-670-82162-4这个数据正常情况应该是输出6-670-82162-X但是你的会输出6-670-82162-4。没能正确改正带X的识别码。


|