为啥自己运行给的例子都对,提交后却一个都不对啊

P1055 [NOIP2008 普及组] ISBN 号码

Tqh456789 @ 2024-11-30 22:03:14

求大佬救救孩子吧

#include <bits/stdc++.h>
using namespace std;
int main()
{
    char a[13];
    cin>>a;
    int sum = 0,k = 0;
    for(int i=0;i<12;i++)
    {
        if(a[i] != '-')
        {
            k++;
            sum += (a[i] - '0') * k;
        }
    }
    int h = sum%11;
    if(h == a[12] - '0')
    {
        cout<<"Right";
    }
    else 
    {
        if(h < 10)
        {
            a[12] = h + '0';
            cout<<a;
        }
        if(h == 10)
        {
            a[12] = 'X';
            cout<<a;
        }
    }
    return 0;
}

by wangrunyang @ 2024-11-30 22:08:27

试试这样改

#include <bits/stdc++.h>
using namespace std;
string a;
int main()
{
    cin>>a;
    int sum = 0,k = 0;
    for(int i=0;i<12;i++)
    {
        if(a[i] != '-')
        {
            k++;
            sum += (a[i] - '0') * k;
        }
    }
    int h = sum%11;
    if(h == a[12] - '0')
    {
        cout<<"Right";
    }
    else 
    {
        if(h < 10)
        {
            a[12] = h + '0';
            cout<<a;
        }
        if(h == 10)
        {
            a[12] = 'X';
            cout<<a;
        }
    }
    return 0;
}

by nicky_mao @ 2024-11-30 22:11:07

@Tqh456789 你没考虑识别码正确且为X的情况


by Tqh456789 @ 2024-11-30 22:36:45

@wangrunyang四鹤六过不了应该少了尾号是X的情况


by Tqh456789 @ 2024-11-30 22:37:57

@nicky_mao卧槽!!!!!!!!!!!!!!!!!,懂了感谢大佬


by Tqh456789 @ 2024-11-30 22:42:14

@wangrunyang为啥在全局变里面加个string a就能通过呢


by wangrunyang @ 2024-12-01 19:01:31

@Tqh456789 啊,我没试,我以为cin>>char[13];是输入不了的,因为你一个数据都没过


|