C++50分求助

P1055 [NOIP2008 普及组] ISBN 号码

KirinRYato @ 2022-10-05 17:32:33

#include<bits/stdc++.h>
using namespace std;
int nums(int a,int b,int c,int d,int e,int f,int g,int h,int i){
    int num=a*1+b*2+c*3+d*4+e*5+f*6+g*7+h*8+i*9;
    num=num%11;
    return num;
}
int main(){
    int a,b,c,d,b1[3],c1[5],num;
    scanf("%d-%d-%d-%d",&a,&b,&c,&d);
    b1[0]=b/100;b1[1]=(b/10)%10;b1[2]=b%10;
    c1[0]=c/10000;c1[1]=(c/1000)%10;c1[2]=(c/100)%10;c1[3]=(c/10)%10;c1[4]=c%10;
    //cout<<a<<endl<<b<<endl<<b1[0]<<endl<<b1[1]<<endl<<b1[2]<<endl<<c<<endl<<c1[0]<<endl<<c1[1]<<endl<<c1[2]<<endl<<c1[3]<<endl<<c1[4]<<endl<<d<<endl;
    num=nums(a,b1[0],b1[1],b1[2],c1[0],c1[1],c1[2],c1[3],c1[4]);
    if(num==d){
        printf("Right");
    }
    else{
        cout<<a<<'-'<<b<<'-'<<c<<'-'<<num;
    }
    return 0;
}

4点、5点、6点、7点、9点WA了


by lxc_awa @ 2022-10-05 17:45:54

@lingaohui 有没有一种可能,你没考虑X


by lxc_awa @ 2022-10-05 17:50:50

#include<bits/stdc++.h>
using namespace std;
int nums(int a,int b,int c,int d,int e,int f,int g,int h,int i){
    int num=a*1+b*2+c*3+d*4+e*5+f*6+g*7+h*8+i*9;
    num=num%11;
    return num;
}
int main(){
    int a,b,c,b1[3],c1[5],num;
    char d;
    scanf("%d-%d-%d-%s",&a,&b,&c,&d);
    b1[0]=b/100;b1[1]=(b/10)%10;b1[2]=b%10;
    c1[0]=c/10000;c1[1]=(c/1000)%10;c1[2]=(c/100)%10;c1[3]=(c/10)%10;c1[4]=c%10;
    //cout<<a<<endl<<b<<endl<<b1[0]<<endl<<b1[1]<<endl<<b1[2]<<endl<<c<<endl<<c1[0]<<endl<<c1[1]<<endl<<c1[2]<<endl<<c1[3]<<endl<<c1[4]<<endl<<d<<endl;
    num=nums(a,b1[0],b1[1],b1[2],c1[0],c1[1],c1[2],c1[3],c1[4]);
    if(num==d-48||num==10&&d=='X'){
        printf("Right");
    }
    else{
        if(num==10){
             cout<<a<<'-'<<b<<'-'<<c<<'-'<<'X';
             return 0;
        }
        cout<<a<<'-'<<b<<'-'<<c<<'-'<<num;
    }
    return 0;
}

这样改


by lxc_awa @ 2022-10-05 17:52:27

求壶关


|