查验身份证 C语言

2023-07-28 19:43:27 浏览数 (1)

碎碎念念

这道题很坑。注意这里的权重是直接乘上去,一开始我乘的是百分之几,死活不知道哪里有问题,后来把一百乘上去,就对了。

代码

代码语言:javascript复制
#include<stdio.h>
int test(char num[])
{
	int i;
	for(i=0;i<17;i  )
	{
		if(num[i]<'0'||num[i]>'9')
		return 0;	
	}
	int sum,z;
	sum=(num[0]-'0')*7 (num[1]-'0')*9 (num[2]-'0')*10 (num[3]-'0')*5 (num[4]-'0')*8 (num[5]-'0')*4 (num[6]-'0')*2 (num[7]-'0')*1 (num[8]-'0')*6 (num[9]-'0')*3 (num[10]-'0')*7 (num[11]-'0')*9 (num[12]-'0')*10 (num[13]-'0')*5 (num[14]-'0')*8 (num[15]-'0')*4 (num[16]-'0')*2;
	z=sum;
	if(z==0)
	{
		if(num[17]!='1')
		return 0;
	}
	else if(z==1)
	{
		if(num[17]!='0')
		return 0;
	}
	else if(z==2)
	{
		if(num[17]!='X')
		return 0;
	}
	else if(num[17]-'0'!=12-z)
	return 0;
	return 1;
}
int main()
{
	int n,tag=0,i;
	scanf("%d",&n);
	char num[n][19];
	for(i=0;i<n;i  )
	scanf("%s",num[i]);	
	for(i=0;i<n;i  )
	{
		if(test(num[i])==0)
		{
			printf("%sn",num[i]);
			tag=1;
		}
	}
	if(tag==0)
	printf("All passed");
}

0 人点赞