AC代码
1 #include <stdio.h> 2 int main () 3 { 4 int amount; 5 scanf("%d",&amount); 6 char input[19]; 7 char ret; 8 int judge = 0 ; //判断是否为ALL PASSED ,是的话为0; 9 while(amount > 0) 10 { 11 scanf("%s",&input); 12 amount--; 13 int i; 14 int sum = 0; 15 int temp; 16 for(i = 0;i < 17;i++) //先检查前17位是否全为数字 若非数字直接跳出循环 17 { 18 if(input[i] < '0' || input[i] > '9') 19 break; 20 } 21 if(i < 17) //i = 17即代表前17都是数字 22 { 23 printf("%s",input); 24 printf(" "); 25 judge = 1; 26 continue; //身份证号出错,直接输出并开始下一轮输入 27 }else 28 if(i == 17) //前17位全为数字则开始检查校验码 29 { 30 for(i = 0;i < 17;i++) 31 { 32 switch(i) 33 { 34 case 0:sum += 7 * (input[i] - '0'); 35 break; 36 case 1:sum += 9 * (input[i] - '0'); 37 break; 38 case 2:sum += 10 * (input[i] - '0'); 39 break; 40 case 3:sum += 5 * (input[i] - '0'); 41 break; 42 case 4:sum += 8 * (input[i] - '0'); 43 break; 44 case 5:sum += 4 * (input[i] - '0'); 45 break; 46 case 6:sum += 2 * (input[i] - '0'); 47 break; 48 case 7:sum += 1 * (input[i] - '0'); 49 break; 50 case 8:sum += 6 * (input[i] - '0'); 51 break; 52 case 9:sum += 3 * (input[i] - '0'); 53 break; 54 case 10:sum += 7 * (input[i] - '0'); 55 break; 56 case 11:sum += 9 * (input[i] - '0'); 57 break; 58 case 12:sum += 10 * (input[i] - '0'); 59 break; 60 case 13:sum += 5 * (input[i] - '0'); 61 break; 62 case 14:sum += 8 * (input[i] - '0'); 63 break; 64 case 15:sum += 4 * (input[i] - '0'); 65 break; 66 case 16:sum += 2 * (input[i] - '0'); 67 break; 68 } 69 } 70 temp = sum % 11; 71 switch(temp) 72 { 73 case 0:ret = '1'; 74 break; 75 case 1:ret = '0'; 76 break; 77 case 2:ret = 'X'; 78 break; 79 case 3:ret = '9'; 80 break; 81 case 4:ret = '8'; 82 break; 83 case 5:ret = '7'; 84 break; 85 case 6:ret = '6'; 86 break; 87 case 7:ret = '5'; 88 break; 89 case 8:ret = '4'; 90 break; 91 case 9:ret = '3'; 92 break; 93 case 10:ret = '2'; 94 break; 95 } 96 if(input[17] == ret) 97 continue; 98 else 99 { 100 printf("%s",input); 101 printf(" "); 102 judge = 1; 103 } 104 } 105 } 106 if(judge == 0) 107 { 108 printf("All passed"); 109 } 110 return 0; 111 }