#4和#7不过啊

P1055 [NOIP2008 普及组] ISBN 号码

WoW0o0 @ 2021-11-09 19:46:39

#include<bits/stdc++.h>
using namespace std;
int main(){
    char ch[13];
    long n;
    for(int i=0;i<13;i++){
        cin>>ch[i];
    }
    n=(ch[0]-'0')*1+(ch[2]-'0')*2+(ch[3]-'0')*3+(ch[4]-'0')*4+(ch[6]-'0')*5+(ch[7]-'0')*6+(ch[8]-'0')*7+(ch[9]-'0')*8+(ch[10]-'0')*9;
    n=n%11;
    if((ch[12]-'0')==n)cout<<"Right";
    else {
        ch[12]=n+'0';
        if((ch[12]-'0')==10){
          for(int j=0;j<12;j++)cout<<ch[j];
          cout<<"X"; 
       } 
        else for(int j=0;j<13;j++)cout<<ch[j];
    }
   return 0;
}

by FQR_ @ 2021-11-09 20:06:03

第11行(输出right的那一行)没判断是否为'X'呀。

if((ch[12]-'0')==n||(n==10&&ch[12]=='X'))cout<<"Right";

by WoW0o0 @ 2021-11-09 20:09:45

@fuqirui▄︻═┳ 感谢大佬


|