0分+样例不过 求助!

P1055 [NOIP2008 普及组] ISBN 号码

liyifanglan @ 2024-07-12 17:26:43

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

int p[10];
int main(){
    int a, b, c, d;
    char d1;
    scanf("%d-%d-%d-%c", &a, &b, &c, &d1);
    p[0] = a, p[1] = b/100, p[2] = b/10%10, p[3] = b%10, p[4] = c/10000, p[5] = c/1000%10, p[6] = c/100%10, p[7] = c/10%10, p[8] = c%10;
    if (int(d1) != 88) d = int(d1)-48;

    int right = 0;
    for (int i = 0; i < 9; i++){
        right += p[i]*i;
    }
    right %= 11;
    if (right == 10){
        right = int('X');
    }
    if (right == d || right == int(d1)) cout << "Right";
    else {
        printf("%d-%d-%d-", a, b, c);
        cout << (right == int('X') ? 'X' : right);
    }
}

by gkyabc @ 2024-07-12 19:12:18

@xd23lyfl

#include<bits/stdc++.h>
using namespace std;
char m[20];
int shi[11];
int aa,bb,cc;
char dd;
int main(){
    cin >> m;
    sscanf(m,"%d-%d-%d-%s",&aa,&bb,&cc,&dd);
    shi[1]=aa;
    shi[2]=bb/100;
    shi[3]=bb/10%10;
    shi[4]=bb%10;
    shi[5]=cc/10000;
    shi[6]=cc/1000%10;
    shi[7]=cc/100%10;
    shi[8]=cc/10%10;
    shi[9]=cc%10;
    for(int i = 1;i<=9;i++){
        shi[10]+=shi[i]*i;
    }
    if(shi[10]%11==dd-'0'||(shi[10]%11==10&&dd==88)){
        cout << "Right"<<endl;
    }else{
        if(shi[10]%11==10){
            cout <<aa<<'-'<<bb<<'-'<<cc<<'-'<<'X';
        }else{
            cout <<aa<<'-'<<bb<<'-'<<cc<<'-'<<shi[10]%11;
        }
    }
    return 0;
}

先求每一位,在比最后一位


by blsya23a2 @ 2024-07-12 19:30:20

a=list(input())
f=a[:]
c=0
for b in range(0,len(a)):
    if a[b-c]=='-':
        del a[b-c]
        c+=1
    elif a[b-c]=='X':
        a[b-c]=10
    else:
        a[b-c]=int(a[b-c])
e=0
for d in range(0,len(a)-1):
    e+=(d+1)*a[d]
if e%11!=10:
    h=e%11
else:
    h='X'
if h==a[-1]:
    print('Right')
elif h=='X' and a[-1]==10:
    print('Right')
else:
    for g in range(0,len(f)-1):
        print(f[g],end='')
    print(h)

by liyifanglan @ 2024-07-12 19:39:02

感谢!!!


by purplepolarstar @ 2024-07-12 21:25:19

你的代码我有一点看不懂。

把我的ACcode给你吧,希望你能看懂(不懂私信),c++的

#include<bits/stdc++.h>
using namespace std;
int main(){
    char a[14],mod[12]="0123456789X";
    cin>>a;
    int i,j=1,t=0;
    for(i=0;i<12;i++){
        if(a[i]=='-') continue;
        t+=(a[i]-48)*j++;
    }
    if(mod[t%11]==a[12]) cout<<"Right";
    else{
        a[12]=mod[t%11];
        cout<<a;
    }
    return 0;
}

|