c++10分求助

P1055 [NOIP2008 普及组] ISBN 号码

LG_Sam @ 2024-06-03 21:16:19

只有7AC


by LG_Sam @ 2024-06-03 21:26:42

微调 1,5,7AC

#include<bits/stdc++.h>
using namespace std;
string isbn;
int main(){
    cin>>isbn;
    int num[10];
    memset(num,0,sizeof(num));
    num[1]=isbn[0]-'0';
    num[2]=isbn[2]-'0';
    num[3]=isbn[3]-'0';
    num[4]=isbn[4]-'0';
    num[5]=isbn[6]-'0';
    num[6]=isbn[7]-'0';
    num[7]=isbn[8]-'0';
    num[8]=isbn[9]-'0';
    num[9]=isbn[10]-'0';
    int sum=0;
    for(int i=1;i<=9;i++){
        sum+=num[i]*i;
    }
    if(isbn[12]=='X'&&sum%11==10){
        cout<<"Right";
    }else if(isbn[12]-'0'==sum%11){ 
        cout<<"Right";
    }else{
        if(isbn[12]=='X') cout<<isbn.substr(1,11)<<"X";
        else cout<<isbn.substr(1,11)<<sum%11;
    }
    return 0;
}

by LG_Sam @ 2024-06-03 21:40:27

又微调了一下 1,3,4,7,8AC```cpp

include<bits/stdc++.h>

using namespace std; string isbn; int main(){ cin>>isbn; int num[10]; memset(num,0,sizeof(num)); num[1]=isbn[0]-'0'; num[2]=isbn[2]-'0'; num[3]=isbn[3]-'0'; num[4]=isbn[4]-'0'; num[5]=isbn[6]-'0'; num[6]=isbn[7]-'0'; num[7]=isbn[8]-'0'; num[8]=isbn[9]-'0'; num[9]=isbn[10]-'0'; int sum=0; for(int i=1;i<=9;i++){ sum+=num[i]*i; } if(isbn[12]=='X'&&sum%11==10){ cout<<"Right"; }else if(isbn[12]-'0'==sum%11){ cout<<"Right"; }else{ if(isbn[12]=='X') cout<<isbn.substr(0,12)<<"X"; else cout<<isbn.substr(0,12)<<sum%11; } return 0; }


by LG_Sam @ 2024-06-03 21:41:40

微调 1,3,4,7,8AC

#include<bits/stdc++.h>
using namespace std;
string isbn;
int main(){
    cin>>isbn;
    int num[10];
    memset(num,0,sizeof(num));
    num[1]=isbn[0]-'0';
    num[2]=isbn[2]-'0';
    num[3]=isbn[3]-'0';
    num[4]=isbn[4]-'0';
    num[5]=isbn[6]-'0';
    num[6]=isbn[7]-'0';
    num[7]=isbn[8]-'0';
    num[8]=isbn[9]-'0';
    num[9]=isbn[10]-'0';
    int sum=0;
    for(int i=1;i<=9;i++){
        sum+=num[i]*i;
    }
    if(isbn[12]=='X'&&sum%11==10){
        cout<<"Right";
    }else if(isbn[12]-'0'==sum%11){ 
        cout<<"Right";
    }else{
        if(isbn[12]=='X') cout<<isbn.substr(0,12)<<"X";
        else cout<<isbn.substr(0,12)<<sum%11;
    }
    return 0;
}

|