80分qj

P1055 [NOIP2008 普及组] ISBN 号码

ZJLmath @ 2022-09-10 17:31:41

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int n[114514]; 
char d[11454];
int main(){
    cin>>d;
    int l=0,x=0;
    int bz=0;
    for(int i=0;i<strlen(d);i++){
        if(d[i]=='-'){
            x++;
            if(x==3){
                bz=d[i+1]-'0';break;
            }
            continue;
        }
        n[l++]=d[i]-'0';
    }
    unsigned long long int cnt=0;
    for(int i=0;i<l;i++){
        cnt+=n[i]*(i+1);
    }
    cnt%=11;
    if(cnt!=bz){
        for(int i=0;i<strlen(d)-1;i++){
            cout<<d[i];
        }
        if(cnt==10)cout<<"X";
        else cout<<cnt;
    }
    else{
        cout<<"Right";
    }
    return 0;
}

by Vanishing_Stars @ 2022-09-10 18:08:15

@ZJL1020math 哦这下我明白了,我试试我改完的能不能AC


by Vanishing_Stars @ 2022-09-10 18:12:31

@ZJL1020math


by Vanishing_Stars @ 2022-09-10 18:14:12

@ZJL1020math 在这段里

for(int i=0; i<strlen(d); i++)
    {
        if(d[i]=='-')
        {
            x++;
            if(x==3)
            {
                if (d[i+1]=='X')
                    bz=10;
                else
                    bz=d[i+1]-'0';
                break;
            }
            continue;
        }
        n[l++]=d[i]-'0';
    }

加了个判断

if (d[i+1]=='X')
                    bz=10;
                else
                    bz=d[i+1]-'0';

by ZJLmath @ 2022-09-10 18:14:43

@CODE_SUPERVISOR 谢谢神犇!


by Vanishing_Stars @ 2022-09-10 18:18:26

@ZJL1020math 不客气


上一页 |