身份证最后一位怎么确认 求路过大神指点
问题是根据输入的身份证号码确认最后一位数字对不对;#include<stdio.h>
#include<string.h>
int main()
{
char st[20];
int T, i, j , sum = 0;
scanf("%d", &T);
while (T--)
{
sum = 0;
scanf("%s", st);
int len;
len = strlen(st);
if (len == 18)
{
for (i = 0; i < 17; i++)
{
switch (i)
{
case 0:sum += (st[i] - '0') * 7; break;
case 1:sum += (st[i] - '0') * 9; break;
case 2:sum += (st[i] - '0') * 10; break;
case 3:sum += (st[i] - '0') * 5; break;
case 4:sum += (st[i] - '0') * 8; break;
case 5:sum += (st[i] - '0') * 4; break;
case 6:sum += (st[i] - '0') * 2; break;
case 7:sum += (st[i] - '0') * 1; break;
case 8:sum += (st[i] - '0') * 6; break;
case 9:sum += (st[i] - '0') * 3; break;
case 10:sum += (st[i] - '0') * 7; break;
case 11:sum += (st[i] - '0') * 9; break;
case 12:sum += (st[i] - '0') * 10; break;
case 13:sum += (st[i] - '0') * 5; break;
case 14:sum += (st[i] - '0') * 8; break;
case 15:sum += (st[i] - '0') * 4; break;
case 16:sum += (st[i] - '0') * 2; break;
}
}
int yu;
yu = sum % 11;
char re;
switch (yu)
{
case 0:re = '1'; break;
case 1:re = '0'; break;
case 2:re = 'X'; break;
case 3:re = '9'; break;
case 4:re = '8'; break;
case 5:re = '7'; break;
case 6:re = '6'; break;
case 7:re = '5'; break;
case 8:re = '4'; break;
case 9:re = '3'; break;
case 10:re = '2'; break;
}
if (re == st[17])
printf("right\n");
else
printf("wrong\n");
}
}
return 0;
}
这个代码在oj上可以通过,但是在电脑上不会运行