70分代码求助

P1055 [NOIP2008 普及组] ISBN 号码

zyq20090215 @ 2022-10-02 15:12:19

#include<bits/stdc++.h>
using namespace std;
string a;
int main()
{
    cin>>a;
    long long n=a.size(),m=1,sum=0,b;
    for(int i=0;i<=n-3;i++)
    {
        if(a[i]>='0'&&a[i]<='9')
        {
            sum+=(a[i]-'0')*m;
            m++;
        }
    }
    b=sum%11;
    if(b==10)b='X';
    else b+='0';
    if(a[n-1]==b)cout<<"Right";
    else
    {
        for(int i=0;i<=n-2;i++)cout<<a[i];
        cout<<sum%11;
    }
    return 0;
}

by jnyz2021109122116 @ 2022-10-02 17:01:48

@zyq20090215 没考虑正确识别码是X


by zyq20090215 @ 2022-10-02 17:19:58

@jnyz2021109122116 过了过了 多谢


|