50分求调

P1055 [NOIP2008 普及组] ISBN 号码

wangshengchen @ 2024-09-28 18:29:01

#include<iostream>
//#include<algorithm>
//#include<cmath>
using namespace std;
int main()
{
    #define int long long
//  #define double long double
    int a,b,c,d;
    char c1,c2,c3;
    cin>>a>>c1>>b>>c2>>c>>c3>>d;
    int s1=a,s2=b/100,s3=(b-s2*100)/10,s4=b-s2*100-s3*10,s5=c/10000,s6=(c-s5*10000)/1000,s7=(c-s5*10000-s6*1000)/100,s8=(c-s5*10000-s6*1000-s7*100)/10,s9=c-s5*10000-s6*1000-s7*100-s8*10,s0=d;
    int s=(s1*1+s2*2+s3*3+s4*4+s5*5+s6*6+s7*7+s8*8+s9*9)%11;
    if(s==s0) cout<<"Right";
    else cout<<a<<c1<<b<<c2<<c<<c3<<s;
    #undef int
    return 0; 
}

by Henry31415926 @ 2024-09-28 18:38:01

“如果余数为 10,则识别码为大写字母 X。”


by laialaodi @ 2024-09-28 18:40:56

校验码是10的时候是X @wangshengchen


by wangshengchen @ 2024-09-28 19:48:47

@Henry31415926 @laialaodi

80了

#include<iostream>
//#include<algorithm>
//#include<cmath>
using namespace std;
int main()
{
    #define int long long
//  #define double long double
    int a,b,c,d;
    char c1,c2,c3;
    cin>>a>>c1>>b>>c2>>c>>c3>>d;
    int s1=a,s2=b/100,s3=(b-s2*100)/10,s4=b-s2*100-s3*10,s5=c/10000,s6=(c-s5*10000)/1000,s7=(c-s5*10000-s6*1000)/100,s8=(c-s5*10000-s6*1000-s7*100)/10,s9=c-s5*10000-s6*1000-s7*100-s8*10,s0=d;
    int s=(s1*1+s2*2+s3*3+s4*4+s5*5+s6*6+s7*7+s8*8+s9*9)%11;
    if(s==s0) cout<<"Right";
    else if(s==10) cout<<a<<c1<<b<<c2<<c<<c3<<"X";
    else cout<<a<<c1<<b<<c2<<c<<c3<<s;
    #undef int
    return 0; 
}

by Henry31415926 @ 2024-09-28 20:07:48

你一开始时应该用 char 存储 d,然后特判 d 是否等于 'X',若是,则把另一个 int 类型的 d1 变量赋值为 10,否则赋值 d1 为 (d - '0')。然后删除 s0 的赋值,并把后文中所有的 s0 改为 d1。

修改后的 AC 代码:

#include<iostream>
//#include<algorithm>
//#include<cmath>
using namespace std;
int main()
{
    #define int long long
//  #define double long double
    int a,b,c;
    char c1,c2,c3,d;
    cin>>a>>c1>>b>>c2>>c>>c3>>d;

    int d1;
    if (d == 'X') d1 = 10;
    else d1 = (d - '0');
    int s1=a,s2=b/100,s3=(b-s2*100)/10,s4=b-s2*100-s3*10,s5=c/10000,s6=(c-s5*10000)/1000,s7=(c-s5*10000-s6*1000)/100,s8=(c-s5*10000-s6*1000-s7*100)/10,s9=c-s5*10000-s6*1000-s7*100-s8*10;
    int s=(s1*1+s2*2+s3*3+s4*4+s5*5+s6*6+s7*7+s8*8+s9*9)%11;
    if(s==d1) cout<<"Right";
    else if (s == 10) cout<<a<<c1<<b<<c2<<c<<c3<<'X';
    else cout<<a<<c1<<b<<c2<<c<<c3<<s;
    #undef int
    return 0; 
}

by Henry31415926 @ 2024-09-28 20:11:07

@wangshengchen


by wangshengchen @ 2024-09-28 20:32:48

@Henry31415926 谢谢 求互关


by Henry31415926 @ 2024-09-28 21:25:12

@wangshengchen 已互关


|