【codeup墓地】21071: ISBN(string)

版权声明:假装有个原创声明……虽然少许博文不属于完全原创,但也是自己辛辛苦苦总结的,转载请注明出处,感谢! https://blog.csdn.net/m0_37454852/article/details/88421344

原题链接

#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
using namespace std;

const int MAX = 10010, INF = (1<<30) - 1;
string str, str2;
int w = 1, S = 0;
int main()
{
	getline(cin, str);
	str2 = str;
	str2.erase(str2.size()-1, 1);
	for(string::iterator it = str.begin(); it != str.end(); it++)
	{
		if(*it == '-') str.erase(it);
	}
	for(int i=0; i<str.size()-1; i++)
	{
		S += (str[i] - '0')*w;
		w++;
	}
	S %= 11;
	if(S == 10) str2 += 'X';
	else str2 += '0'+S;
	if(str2[str2.size()-1] == str[str.size()-1]) cout<<"Right"<<endl;
	else cout<<str2<<endl;
	return 0;
}

猜你喜欢

转载自blog.csdn.net/m0_37454852/article/details/88421344