|
发表于 2019-3-9 14:41:45
|
显示全部楼层
话说你这写法。。学了数组就用起来啊,别一串if,看着头大,自己也不好改
- #include <iostream>
- using namespace std;
- const int weight[] = { 7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2 };
- const char M[] = { '1','0','X','9','8','7','6','5','4','3','2' };
- bool islegal(char* nums) {
- int Z = 0;
- for (int i = 0; i < 17; ++i) {
- Z += weight[i] * (nums[i] - '0');
- }
- Z %= 11;
- return (M[Z] == nums[17]);
- }
- int main() {
- int N;
- char nums[100][19];
- cout << "请输出需要检验的身份证号码的数目:";
- cin >> N;
- cout << "需要检验的身份证号码的数目为:" << N << "\n\n请输入需要检验的身份证号:\n";
- for (int i = 0; i < N; ++i) {
- cin >> nums[N];
- }
- bool Allpassed = true;
- for (int i = 0; i < N; ++i) {
- if (!islegal(nums[N])) {
- if (Allpassed) {
- Allpassed = false;
- cout << "有问题的身份证号为:\n";
- }
- cout << nums[N] << endl;
- }
- }
- if (Allpassed) {
- cout << "All passed!" << endl;
- }
- system("pause");
- }
复制代码 |
|