文章

43

粉丝

180

获赞

21

访问

180.3k

头像
c++
P1722 北京理工大学2017年机试题
发布于2022年4月30日 16:07
阅读数 4.8k

#include <iostream>
using namespace std;

string id;
int val[17] = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};
char mp[11] = {'1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'};

bool check(string s)
{
	if (s.size() != 18) return false;
	int c = 0;
	for (int i = 0; i < s.size() - 1; i ++ )
		c += val[i] * (s[i] - '0');
	if (mp[c % 11] == s[17]) return true;
	else return false;
}

int main()
{
	while (cin >> id) 
		if (check(id)) puts("ID Corrent");
		else puts("ID Wrong");
	return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发