蒟蒻求助50分!

P1055 [NOIP2008 普及组] ISBN 号码

_TheCat @ 2024-04-29 19:04:32

测试点4、5、6、7、9过不了,求各位大佬指点

#include<bits/stdc++.h>
using namespace std;
int lau_1bit,chu_3bit,id_5bit,read_code;
int right_read_code;
int main(){
    scanf("%1d-%3d-%5d-%1d",&lau_1bit,&chu_3bit,&id_5bit,&read_code);
    right_read_code+=lau_1bit;
    right_read_code+=chu_3bit/100*2;
    right_read_code+=(chu_3bit%100/10)*3;
    right_read_code+=(chu_3bit%10)*4;
    right_read_code+=(id_5bit/10000)*5;
    right_read_code+=(id_5bit%10000/1000)*6;
    right_read_code+=(id_5bit%1000/100)*7;
    right_read_code+=(id_5bit%100/10)*8;
    right_read_code+=(id_5bit%10)*9;
    right_read_code=right_read_code%11;
    if(right_read_code==read_code) cout<<"Right";
    else printf("%d-%d-%d-%d",lau_1bit,chu_3bit,id_5bit,right_read_code);
    return 0;
}

by _TheCat @ 2024-04-29 19:09:07

改了一下,4、7过不了

#include<bits/stdc++.h>
using namespace std;
int lau_1bit,chu_3bit,id_5bit,read_code;
int right_read_code;
int main(){
    scanf("%1d-%3d-%5d-%1d",&lau_1bit,&chu_3bit,&id_5bit,&read_code);
    right_read_code+=lau_1bit;
    right_read_code+=chu_3bit/100*2;
    right_read_code+=(chu_3bit%100/10)*3;
    right_read_code+=(chu_3bit%10)*4;
    right_read_code+=(id_5bit/10000)*5;
    right_read_code+=(id_5bit%10000/1000)*6;
    right_read_code+=(id_5bit%1000/100)*7;
    right_read_code+=(id_5bit%100/10)*8;
    right_read_code+=(id_5bit%10)*9;
    right_read_code=right_read_code%11;
    if(right_read_code==read_code) cout<<"Right";
    else{
        printf("%d-%d-%d-",lau_1bit,chu_3bit,id_5bit);
        if(right_read_code==10) cout<<'X';
        else cout<<right_read_code;
    }
    return 0;
}

by Ew_Cors @ 2024-04-29 19:19:11

@ProgrammingCat 给你一个数据:

1-000-00001-X

正确答案:

Right

by Crisp_lrc @ 2024-05-01 00:12:22

@Ew_Cors 感谢大佬,把这种情况忽略掉了


by _TheCat @ 2024-05-01 10:30:08

@Ew_Cors 感谢大佬


|