70分求助

P1055 [NOIP2008 普及组] ISBN 号码

Xuancheng_Mao @ 2023-06-20 18:34:01

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    char e,f,g,d;
    cin>>a>>e>>b>>f>>c>>g>>d;
    int a1,b1,c1,d1,e1,f1,g1,h1,i1;
    a1=a; //1
    b1=b/100; //2
    c1=b%100/10; //3
    d1=b%10; //4
    e1=c/10000; //5
    f1=c%10000/1000; //6
    g1=c%1000/100; //7
    h1=c%100/10; //8;
    i1=c%10; //9;
    int x=a1*1+b1*2+c1*3+d1*4+e1*5+f1*6+g1*7+h1*8+i1*9;
    x=x%11;
    if(d=='X')
    {
        if(x==10)
        {
            cout<<"Right";
        }
        else
        {
            cout<<a<<"-"<<b<<"-"<<c<<"-"<<x%11;
        }
    }
    else
    {
        int y=d;
        y=y-48;
        if(x==y)
        {
            cout<<"Right";
        }
        else
        {
            cout<<a<<"-"<<b<<"-"<<c<<"-"<<x%11;
        }
    }
    return 0;
}

by zwyyy @ 2023-06-20 18:40:40


by Xuancheng_Mao @ 2023-06-20 19:07:38

@zwyyy 更正后也只有80分 把x的数据类型改成了 long long,判断语句中的x改为了x%11

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    char e,f,g,d;
    cin>>a>>e>>b>>f>>c>>g>>d;
    int a1,b1,c1,d1,e1,f1,g1,h1,i1;
    a1=a; //1
    b1=b/100; //2
    c1=b%100/10; //3
    d1=b%10; //4
    e1=c/10000; //5
    f1=c%10000/1000; //6
    g1=c%1000/100; //7
    h1=c%100/10; //8;
    i1=c%10; //9;
    long long x=a1*1+b1*2+c1*3+d1*4+e1*5+f1*6+g1*7+h1*8+i1*9;
    if(d=='X')
    {
        if(x%11==10)
        {
            cout<<"Right";
        }
        else
        {
            cout<<a<<"-"<<b<<"-"<<c<<"-"<<x%11;
        }
    }
    else
    {
        int y=d;
        y=y-48;
        if(x%11==y)
        {
            cout<<"Right";
        }
        else
        {
            cout<<a<<"-"<<b<<"-"<<c<<"-X";
        }
    }
    return 0;
}

by zwyyy @ 2023-06-20 19:18:20

@Xuancheng_Mao 你看错我写的第二条了,我说当x=10且d不等于X时啊


by Xuancheng_Mao @ 2023-07-10 15:40:31

@zwyyy 已经解决了 谢谢!


by zwyyy @ 2023-07-11 09:30:58

@Xuancheng_Mao 关注@zwyyy 谢谢喵


|