doubaobao @ 2024-06-22 12:26:18
#include<iostream>
#include<cmath>
using namespace std;
int main(){
int first,second[4],third[6],fourth;
char wast[3],speaceX;
cin>>first>>wast[1]>>second[4]>>wast[1]>>third[6]>>wast[1]>>fourth;
second[1]=second[4]/100;
second[2]=(second[4]/10)-(second[1]*10);
second[3]=second[4]-(second[1]*100)-(second[2]*10);
/*******************************************************************/
third[1]=third[6]/10000;
third[2]=(third[6]/1000)-(third[1]*10);
third[3]=(third[6]/100)-((third[1]*100)+(third[2]*10));
third[4]=(third[6]/10)-((third[1]*1000+(third[2]*100)+(third[3]*10)));
third[5]=third[6]-((third[1]*10000)+(third[2]*1000)+(third[3]*100)+(third[4]*10));
int newsecond[9];
newsecond[1]=(first*1)+(second[1]*2)+(second[2]*3)+(second[3]*4)+(third[1]*5)+(third[2]*6)+(third[3]*7)+(third[4]*8)+(third[5]*9);
if(newsecond[1]%11==fourth){
cout<<"Right"; return 0;
}if(newsecond[1]%11==10 and speaceX=='X'){
cout<<"Right"; return 0;
}
if(newsecond[1]%11==10 and speaceX!='X'){
cout<<first<<wast[1]<<second[1]<<second[2]<<second[3]<<wast[1]<<third[1]<<third[2]<<third[3]<<third[4]<<third[5]<<wast[1]<<"X";
return 0;
}
if(newsecond[1]%11!=fourth){
newsecond[2]=newsecond[1]%11;
cout<<first<<wast[1]<<second[1]<<second[2]<<second[3]<<wast[1]<<third[1]<<third[2]<<third[3]<<third[4]<<third[5]<<wast[1]<<newsecond[2];
return 0;
}
if(newsecond[1]%11!=10 and speaceX=='X'){
newsecond[2]=newsecond[1]%11;
cout<<first<<wast[1]<<second[1]<<second[2]<<second[3]<<wast[1]<<third[1]<<third[2]<<third[3]<<third[4]<<third[5]<<wast[1]<<newsecond[2];
return 0;
}
return 0;
}
第四和第七个测试点WA了 不知道为什么 80分
by wangjingxi_ @ 2024-06-22 14:04:06
@doubaobao
#include<cstring>
using namespace std;
int main(){
string isbn;
cin >> isbn;
// 分解输入的ISBN码
int first = isbn[0] - '0';
int second1 = isbn[2] - '0';
int second2 = isbn[3] - '0';
int second3 = isbn[4] - '0';
int third1 = isbn[6] - '0';
int third2 = isbn[7] - '0';
int third3 = isbn[8] - '0';
int third4 = isbn[9] - '0';
int third5 = isbn[10] - '0';
char original_check_digit = isbn[12];
// 计算新的校验码
int new_check_digit = (first*1 + second1*2 + second2*3 + second3*4 +
third1*5 + third2*6 + third3*7 + third4*8 + third5*9) % 11;
// 判断校验码是否正确
if ((new_check_digit < 10 && original_check_digit == new_check_digit + '0') ||
(new_check_digit == 10 && original_check_digit == 'X')) {
cout << "Right";
} else {
// 输出正确的ISBN码
cout << isbn.substr(0, 12);
if (new_check_digit == 10) {
cout << 'X';
} else {
cout << new_check_digit;
}
}
return 0;
}
by wangjingxi_ @ 2024-06-22 14:10:30
@doubaobao 求关注
by doubaobao @ 2024-06-22 14:15:39
@wangjingxi_ 谢谢大佬