CCF 201312-2 ISBN号码(满分)

#include<iostream>
#include<string>
using namespace std;

int main()
{
    
    
	string str;
	cin >> str;
	int num = 0,weight = 1;
	for (int i = 0; i < str.size()-1; i++) {
    
    
		if (str[i] == '-')  continue;
		num += (str[i] - '0')*weight;// (s[i]-'0') 注意此处,容易出错
		weight++;                    // (s[i]-'0')将字符转换为数字
	}
	char number;
	if (num % 11 == 10) number = 'X';
	else number = num % 11 + '0'; // 将数字转换为字符

	if (str[str.size() - 1] == number) cout << "Right" << endl;
	else {
    
    
		str[str.size() - 1] = number;
		cout << str << endl;
	}

	system("pause");
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_27538633/article/details/105797237