欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

201312-2ISBN编码

发布时间:2025/6/17 编程问答 51 豆豆
生活随笔 收集整理的这篇文章主要介绍了 201312-2ISBN编码 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

//100分,进步的是使用了isdigit()函数判断字符是不是英文字母
#include<iostream>
#include<string>
#include<cctype>
using namespace std;
int main(){
string str;
cin>>str;
int a[10];
int len,i,sum = 0,j = 0;
len = str.length();
for(i=0;i<len-1;i++){
if(isdigit(str[i])){
a[j] = str[i] - '0';
j++;
}
}
for(i=0;i<j;i++){
sum += a[i]*(i+1);
}
if(isdigit(str[len-1])){
a[9] = str[len-1] - '0';
if(sum%11 == a[9]) cout<<"Right";
else {
if(sum%11==10) {
str[len-1] = 'X';
cout<<str;
}
else {
str[len-1] = sum%11+'0';
cout<<str;
}

}
}
else {
if(sum%11==10) cout<<"Right";
else {
str[len-1] = sum%11+'0';
cout<<str;
}
}

return 0;
}

转载于:https://www.cnblogs.com/whitehouse2016/p/6568107.html

总结

以上是生活随笔为你收集整理的201312-2ISBN编码的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。