正常模拟就好了,可以画一个分支会更清晰一
2025-10-24 16:40:35
发布于:浙江
0阅读
0回复
0点赞
#include<iostream>
#include<string>
using namespace std;
string str;
string temp;
bool flag = false;
long long sum;
int main() {
cin >> str;
int len = str.size();
for (int i = 0; i < len - 1; i++) {
if (str[i] != '-')
temp += str[i];
}
for (int i = 0; i < 9; i++) {
sum += (temp[i] - '0') * (i + 1);
}
int res = sum % 11;
if (res == 10) flag = true;
//cout<<res<<endl;
//cout<<str[12]<<endl;
//cout << flag << endl;
//先把前面的所有位置输出,还要判断ISBN码
if (flag) {
if (str[12] == 'X') {
cout << "Right";
} else {
for (int i = 0; i < 12; i++) {
cout << str[i];
}
cout << "X";
}
} else {
if (str[12]-'0' == res) {
cout << "Right";
} else {
for (int i = 0; i < 12; i++) {
cout << str[i];
}
cout << res;
}
}
return 0;
}
这里空空如也


有帮助,赞一个