TJ
2025-05-06 19:20:56
发布于:重庆
1阅读
0回复
0点赞
相当的基础
#include <iostream>
#include <string>
using namespace std;
int main() {
string isbn;
cin >> isbn;
string digits;
char check_digit;
for (char c : isbn) {
if (isdigit(c)) {
if (digits.length() < 9) {
digits += c;
} else {
check_digit = c;
break;
}
}
}
int sum = 0;
for (int i = 0; i < 9; ++i) {
int digit = digits[i] - '0';
sum += digit * (i + 1);
}
int remainder = sum % 11;
char correct_check = (remainder == 10) ? 'X' : ('0' + remainder);
if (check_digit == correct_check) {
cout << "Right" << endl;
} else {
for (int i = 0; i < isbn.length() - 1; ++i) {
cout << isbn[i];
}
cout << correct_check << endl;
}
return 0;
}
这里空空如也
有帮助,赞一个