题解 | #奇偶校验#
奇偶校验
https://www.nowcoder.com/practice/729d11d043d8448e83befa1410b694fe
#include <stdio.h> #include <string.h> #include<stdlib.h> int main() { char a[100]; while (scanf("%s", &a) != EOF) { // 注意 while 处理多个 case // 64 位输出请用 printf("%lld") to //printf("%s:%d\n", &a,strlen(&a)); int i,j; //校验输入的合法性 for(i=0;i<strlen(&a);i++){ if((a[i]>='0'&&a[i]<='9')||(a[i]>='a'&&a[i]<='z')||(a[i]>='A'&&a[i]<='Z')){ int x=a[i],m,count=0; char outString[9]={'0'}; for(m=8-1;m>=0;m--){ if(x%2==1) count++; outString[m]=(x%2+48); x=x/2; } if(count%2==0) outString[0]='1'; outString[8]='\0'; printf("%s\n",&outString); continue; } printf("输入不合法\n"); } } return 0; }