为什么,只有50分,求助

P1055 [NOIP2008 普及组] ISBN 号码

DKsniper @ 2023-08-21 10:12:11

#include<bits/stdc++.h>
using namespace std;
int n,a[12],ans,aa,b;
char c;
int main()
{
    cin>>a[1]>>c>>aa>>c>>b>>c>>a[10];
    a[4]=aa%10,a[3]=aa/10%10,a[2]=aa/100;
    a[9]=b%10,a[8]=b/10%10,a[7]=b/100%10,a[6]=b/1000%10,a[5]=b/10000;
    for(int i=1;i<=9;i++)
    {
        ans+=a[i]*i;
    }
    int vi=ans%11;
    if(vi==a[10]) cout<<"Right";
    else cout<<a[1]<<c<<aa<<c<<b<<c<<vi;
    return 0;
}

by OIerWu_829 @ 2023-08-21 10:14:14

AC Code

#include <bits/stdc++.h>
using namespace std;

int main()
{
    char a[100];
    scanf("%c-%c%c%c-%c%c%c%c%c-%c", &a[0], &a[1], &a[2], &a[3], &a[4], &a[5], &a[6], &a[7], &a[8], &a[9]);
    int sum = 0,remainder;
    char ch;
    for (int i = 0; i < 9; i++)
    {
        sum += (a[i] - '0') * (i + 1);
    }
    remainder = sum % 11;
    if (remainder == 10) ch = 'X';
    else ch = remainder + '0';
    if (ch == a[9]) printf("Right\n");
    else
        printf("%c-%c%c%c-%c%c%c%c%c-%c\n", a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], ch);
    return 0;
}

by DKsniper @ 2023-08-21 11:47:24

@wzj0829

谢谢,AC了


|