按要求模拟匹配即可
2024-03-21 14:56:30
发布于:浙江
14阅读
0回复
0点赞
题目难度不大,直接按要求模拟匹配即可。
#include <bits/stdc++.h>
using namespace std;
int main(){
int a[]={7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};
char checkCodes[] = "10X98765432";
string idcard;
cin>>idcard;
if (idcard.length()!=18){
cout<<"No"<<endl;
return 0;
}
int total = 0;
for (int i = 0; i < 17; i++) {
int digit = idcard[i] - '0';
int weight = a[i];
total += digit * weight;
}
int checkCodeIndex = total % 11;
if (idcard[17] == checkCodes[checkCodeIndex]) {
cout<<"Yes"<<endl;
return 0;
} else {
cout<<"No"<<endl;
return 0;
}
}
这里空空如也
有帮助,赞一个