0
点赞
收藏
分享

微信扫一扫

【2017】ISBN编码(字符串处理)(水题)

追风骚年 2022-03-12 阅读 52
算法

题目:

#include<iostream>
#include<string>
using namespace std;
int mp[10] = { 10,9,8,7,6,5,4,3,2 };
int main() {
	string str;
	cin >> str;
	int cnt = 0,x=0;
	for (int i = 0; i < str.length(); i++) {
		if (str[i] >= '0'&&str[i] <= '9') {
			x += (str[i] - '0')*mp[cnt++];
		}
		cout << str[i];
	}
	x =11 - x % 11;
	if (x >= 1 && x <= 9)
		cout << '-' << x;
	else if (x == 10)
		cout << '-' << 'X';
	else if (x == 11)
		cout << '-' << '0';
	system("pause");
	return 0;
}

 

举报

相关推荐

0 条评论