文章
47
粉丝
109
获赞
8
访问
28.3k
#include<stdio.h>
#include<string.h>
int main() {
char s[105];
int f[17] = { 7 ,9, 10, 5 ,8 ,4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 };//前十七位的权值
while (gets(s) != NULL) {
int len = strlen(s);
int sum = 0;//前面权值相乘后相加
int x = 0;//余数
if (len != 18) {
printf("ID Wrong\n");
continue;
}
for (int i = 0; i <= 16; i++) {
sum = sum + f[i] * (s[i] - '0');//-'0'表示强转为int 型
}
x = sum % 11;
/*printf("%d\n", x);*/
int flag = 0;
switch (x) {
case 0:
if ((s[17] - '0') == 1) {
flag = 1;
printf("ID Corrent\n");
}
break;//合法输出ID correct 否则 ID wrong,也就是只能比一次
case 1:
if ((s[17] - '0') == 0) {
flag = 1;
printf("ID Corrent\n");
}
break;
case 2:
if (s[17] == 'X') {
flag = 1;
printf("ID Corrent\n");
}
break;
case 3:
if ((s[17] - '0') == 9) {
flag = 1;
printf("ID Corrent\n");
}
break;
case 4:
...
登录后发布评论
暂无评论,来抢沙发