求助解法!!!

P1055 [NOIP2008 普及组] ISBN 号码

1998ikun0802 @ 2021-08-30 16:02:11

这道题WA了五个测试点,我觉得错误一定和X有关。但是就是不知道怎么写代码啊!所以来求助一下大家在输入和输出时有X应该怎么写代码!错误代码如下

#include<iostream>
using namespace std;
int main()
{
    int a,b,c,d,x1,x2,x3,x4,x5,x6,x7,x8,x9,r,R;
    cin>>a>>b>>c>>d;
    b=0-b;
    c=0-c;
    d=0-d;
    x1=a;
    x2=b/100;
    x3=b/10%10;
    x4=b%10;
    x5=c/10000;
    x6=c/1000%10;
    x7=c/100%10;
    x8=c/10%10;
    x9=c%10;
    r=x1*1+x2*2+x3*3+x4*4+x5*5+x6*6+x7*7+x8*8+x9*9;
    R=r%11;
    if(d==R)
    {
        cout<<"Right";
    }
    else
    {
        cout<<a<<"-"<<b<<"-"<<c<<"-"<<R;
    }
    return 0;
}

by Bowen123 @ 2021-08-30 16:14:37

@安小妮

加一句

if(r==10)
    cout<<a<<"-"<<b<<"-"<<c<<"-"<<"X";

就可以了吧


by 1998ikun0802 @ 2021-08-30 17:40:43

@Bowen123 加在哪啊?我觉得应该不行叭,那right的情况怎么办吖


by Bowen123 @ 2021-08-30 19:05:16

@安小妮

翻看一下题解吧

这种东西还是自行理解比较好


by 1998ikun0802 @ 2021-08-31 19:32:54

@Bowen123 az


by 精神小伙! @ 2021-09-01 20:59:57

@安小妮 代码

#include<iostream>
using namespace std;
int main()
{
    int a,b,c,x1,x2,x3,x4,x5,x6,x7,x8,x9,r,R;
    char d,x,y,z;
    cin>>a>>x>>b>>y>>c>>z>>d;
    x1=a;
    x2=b/100;
    x3=b/10%10;
    x4=b%10;
    x5=c/10000;
    x6=c/1000%10;
    x7=c/100%10;
    x8=c/10%10;
    x9=c%10;
    r=x1*1+x2*2+x3*3+x4*4+x5*5+x6*6+x7*7+x8*8+x9*9;
    R=r%11;
    if(d=='X'&&R==10)
    {
        cout<<"Right"<<endl;
        return 0;
    }
    else
    {
        if(R==d-'0')
        {
            cout<<"Right";
            return 0; 
        }
        if(R==10)  cout<<a<<"-"<<b<<"-"<<c<<"-X";
        else       cout<<a<<"-"<<b<<"-"<<c<<"-"<<R;
    }
    return 0;
}

by 1998ikun0802 @ 2021-09-01 21:33:42

@精神小伙! 谢谢你哈,题已经通过了。但是我想问一下那个if(R==d-'0')是啥意思


by 精神小伙! @ 2021-09-02 17:44:25

@安小妮 把 d 由字符串转成数字(来自蒟蒻的小声回答)


by 1998ikun0802 @ 2021-09-04 21:31:12

@精神小伙! 那为啥要减‘0’嘞


by 精神小伙! @ 2021-09-07 17:16:37

@安小妮 我也不知道awa


by 1998ikun0802 @ 2021-09-08 21:41:36

@精神小伙! 噢


|