/* 根据身份证前17位计算最后一位 */
char last(char *id)
{
int sum = 0;
for (int i = 0; i < 17; i++)
sum = sum * 2 + id[i] - 48;
int mod = (sum * 20 + 1) % 11;
return mod == 10 ? 'X' : mod + 48;
}
int main(void)
{
printf("m = %c\n", last("12345620050607538m"));
return 0;
}
def last(id):
sum = 0;
for i in range(0, 17):
sum = sum * 2 + int(id[i])
mod = (sum * 20 + 1) % 11
return 'X' if mod == 10 else str(mod)
if __name__ == '__main__':
print("m = " + last("12345620050607538m"))