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 ZJLmath @ 2022-09-10 17:40:33

在线等答案!!!!!!!!!


by hou_c_j @ 2022-09-10 17:41:02

X的判断 输入6-670-82162-X 输出6-670-82162-X×


by Vanishing_Stars @ 2022-09-10 17:41:09

@ZJL1020math 我是帮你改还是给我的程序你自己看


by ZJLmath @ 2022-09-10 17:48:39

@CODE_SUPERVISOR 可以帮我改改吗?


by Vanishing_Stars @ 2022-09-10 17:49:55

@ZJL1020math 行,那我看看


by Vanishing_Stars @ 2022-09-10 17:53:09

@ZJL1020math 能说一下你每个变量是干啥的吗


by Vanishing_Stars @ 2022-09-10 17:54:28

@ZJL1020math 没搞懂你申请bz有啥用,是要判断余数是否为零嘛?假如是,那直接cnt%11==0就行了哈哈


by Vanishing_Stars @ 2022-09-10 17:54:56

打错了是!=


by ZJLmath @ 2022-09-10 18:02:42

@CODE_SUPERVISOR 说白了就是不想找最后的验证码,就用bz存了一下,最后和算出来的cnt对比


by Vanishing_Stars @ 2022-09-10 18:05:30

@ZJL1020math 哦好的,我理解错了hhh


| 下一页