文章

49

粉丝

90

获赞

90

访问

38.0k

头像
身份证校验 题解:C++
P1722 北京理工大学机试题
发布于2024年3月7日 21:22
阅读数 783

#include<iostream>
using namespace std;

void error()
{
	cout << "ID Wrong" << endl;
}

void corrent()
{
	cout << "ID Corrent" << endl;
}
int main()
{
	string s;
	while (cin >> s)
	{
		int n = s.size();
		if (n != 18)
			error();
		else
		{
			int x = s[0] * 7 + s[1] * 9 + s[2] * 10 + s[3] * 5 + s[4] * 8 + s[5] * 4 + s[6] * 2 + s[7] + s[8] * 6 + s[9] * 3 + s[10] * 7 + s[11] * 9 + s[12] * 10 + s[13] * 5 + s[14] * 8 + s[15] * 4 + s[16] * 2 - 4800;//4800自己算出来的
			if (s[17] == 'X')
			{
				x %= 11;
				if (x == 2)
					corrent();
				else
					error();
			}
			else
			{
				x += s[17] - 48;//‘0’=48
				x %= 11;
				if (x == 1)
					corrent();
				else
					error();
			}
		}
	}
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发