测试点#5,#6,#9WA了,求大佬解答

P1055 [NOIP2008 普及组] ISBN 号码

President_Zhao @ 2023-07-26 09:33:13

#include<bits/stdc++.h>
using namespace std;
string a;
string b;
long long s=1,total=0;
int main()
{
    cin>>a;
    for(int d=0;d<13;d++)
    {
        if(d==1 || d==5 ||d==11)
        {
            continue;
        }
        b[s]=a[d];
        s++;
    }
    for(int q=1;q<=9;q++)
    {
        if(b[9]=='X')
        {
            //b[9]=10;
            total+=10*q;
            break;
        }
        else
        total+=((b[q]-'0')*q);
    }
    total=total%11;
    if(total==10)
    {
        total='X';
    }
    if(total=='X'&&b[10]=='X')
    {
        cout<<"Right";
        return 0;
    }
    if((total+'0')==b[10])
    {
        cout<<"Right";
    }
    else
    {
        for(int q=0;q<12;q++)
        {
            cout<<a[q];
        }
        cout<<total;
    }
}

by MTF_Lambda_04 @ 2023-07-26 09:34:27

@ZZYjinitaimei 仅供参考

#include<iostream>
#include<cstring>
using namespace std;
int main(){
    char s[20];
    cin>>s;
    int len=strlen(s);
    int k=1,y=0;
    for(int i=0;i<=len-2;i++){
        if(s[i]=='-'){
            continue;
        }else{
            y=y+k*(s[i]-'0');
            k++;
        }
    }
    y=y%11;
    char c=y+'0';
    if(y==10){
        c='X';
    }
    if(c==s[len-1]){
        cout<<"Right";
    }else{
        for(int i=0;i<=len-2;i++){
            cout<<s[i];
        }
        cout<<c;
    }
    return 0;
}

by President_Zhao @ 2023-07-26 09:38:40

@MTF_Birdwatchers 谢谢大佬!


by MTF_Lambda_04 @ 2023-07-26 09:40:28

@ZZYjinitaimei 我不是大佬我还是一只蒻得不能再蒻的蒟蒻(如果您不介意的话我想要个关注


by President_Zhao @ 2023-07-26 09:42:11

@MTF_Birdwatchers 没事,关注啦!


by MTF_Lambda_04 @ 2023-07-26 09:43:06

@ZZYjinitaimei Very Thanks!


by dienter @ 2023-07-27 17:28:41

@ZZYjinitaimei 警钟长鸣一下,这里输入不仅要加一个X的特判,输出也要!


by President_Zhao @ 2023-07-28 09:00:33

@dienter OK,谢谢大佬!


|