1. 程式人生 > >C. 身份證號碼最後一位

C. 身份證號碼最後一位

在這裡插入圖片描述

#include <stdio.h>
void zi()
{
	char a[18];
	int z;
	scanf("%s",a);
	z=(a[0]-'0')*7+(a[1]-'0')*9+(a[2]-'0')*10+(a[3]-'0')*5+(a[4]-'0')*8+(a[5]-'0')*4+(a[6]-'0')*2+(a[7]-'0')*1+(a[8]-'0')*6+(a[9]-'0')*3+(a[10]-'0')*7+(a[11]-'0')*9+(a[12]-'0')*10+(a[13]-'0')*5+(a[14]-'0')*8+(a[15]-'0')*4+(a[16]-'0')*2;
	int
x; x=z%11; int c; if(x== 0) c=1; else if(x==1) c=0; else if(x==2) c=40; else if(x==3) c=9; else if(x==4) c=8; else if(x==5) c=7; else if(x==6) c=6; else if(x==7) c=5; else if(x==8) c=4; else if(x==9) c=3; else if(x==10) c=2; if(c==a[17]-'0') printf("right\n");
else printf("wrong\n"); } int main(void) { int a; scanf("%d",&a); for(;a>0;a--) { zi(); } return 0; }

親測可過