ISBN号码
2023-09-15 17:40:23
发布于:上海
24阅读
0回复
0点赞
#include <iostream>
#include <string>
using namespace std;
string validateIDCard(const string& idCard) {
if (idCard.length() != 18) {
return "No";
}
int weights[] = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};
char checkCodes[] = "10X98765432";
int total = 0;
for (int i = 0; i < 17; i++) {
int digit = idCard[i] - '0';
int weight = weights[i];
total += digit * weight;
}
int checkCodeIndex = total % 11;
if (idCard[17] == checkCodes[checkCodeIndex]) {
return "Yes";
} else {
return "No";
}
}
int main() {
string idCard;
cin >> idCard;
string result = validateIDCard(idCard);
cout << result << endl;
return 0;
}
这里空空如也
有帮助,赞一个