80分求调!

P1055 [NOIP2008 普及组] ISBN 号码

M_lzy @ 2024-08-30 10:55:44

80分求调!!!!!!!

#include<bits/stdc++.h>
using namespace std;
int a[100005];
int main(){
    string s;
    cin>>s;
    int p=1;
    for(int i=0;i<=10;i++){
        if(s[i]>='0' and s[i]<='9'){
            a[p]=s[i]-'0';
            p++;
        }
    }
    p=1;
    long long sum=0;
    for(int i=1;i<=9;i++){
        sum+=a[i]*p;
        p++;
    }
    int ans=s[12]-'0';
    if(sum%11==ans) cout<<"Right";
    else{
        if(sum%11==10){
            s[12]='X';
        }
        else{
            s[12]=sum%11+'0';
        }
        cout<<s;
    }
    return 0;
}

by HuangSiHan3116 @ 2024-08-30 11:01:06

为什么要用数组,好好写它不香吗?

#include<bits/stdc++.h>
using namespace std;
int main() {
    int a1,a2,a3,a4,a5,a6,a7,a8,a9;
    char x;
    scanf("%1d-%1d%1d%1d-%1d%1d%1d%1d%1d-%c",&a1,&a2,&a3,&a4,&a5,&a6,&a7,&a8,&a9,&x);
    if(x=='X'){
        x=10;
    }else{
        x=x-'0';
    }
    long long X=(a1+a2*2+a3*3+a4*4+a5*5+a6*6+a7*7+a8*8+a9*9)%11;
    if(X==x){
        printf("Right\n");
    }else{
        if(X==10){
            printf("%1d-%1d%1d%1d-%1d%1d%1d%1d%1d-X",a1,a2,a3,a4,a5,a6,a7,a8,a9);
        }else{
            printf("%1d-%1d%1d%1d-%1d%1d%1d%1d%1d-%1d",a1,a2,a3,a4,a5,a6,a7,a8,a9,X);
        }
    }
    return 0;
}

求关


by M_lzy @ 2024-08-30 11:03:40

@HuangSiHan3116 谢谢dalao


by Super_Cube @ 2024-08-30 11:06:25

@M_lzy 你代码的第 20 行有误,应改为 int ans=(s[12]=='X'?'0'+10:s[12])-'0';


by M_lzy @ 2024-08-30 11:09:37

@Super_Cube AC了,dalao爱你


by X__zy @ 2024-08-30 11:35:39

@M_lzy ```cpp

include<iostream>

using namespace std; int main(){ char a[14],mod[12]="0123456789X"; scanf("%s",a); / for(int i=0;i<12;i++){ cin>>a[i]; } / 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]; printf("%s",a); /for(int i=0;i<13;i++){ cout<<a[i]; } */ } return 0; }


by X__zy @ 2024-08-30 11:36:22

#include<iostream>
using namespace std;
int main(){
    char a[14],mod[12]="0123456789X";
    scanf("%s",a);
    /*
       for(int i=0;i<12;i++){
           cin>>a[i];
       }
    */
    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];
        printf("%s",a);
        /*for(int i=0;i<13;i++){
            cout<<a[i];
        }
        */
    }
    return 0;
}

@M_lzy


|