题解 | #奇偶校验#
奇偶校验
https://www.nowcoder.com/practice/729d11d043d8448e83befa1410b694fe
#include <iostream> using namespace std; int* bin(int a){ int num=7,cou=0; static int ans[8];; do{ ans[num--]=a%2; if(a%2==1){ cou++; } a/=2; }while(a!=0); ans[0]=(cou+1)%2; return ans; } int main() { char a; int b; while (cin >> a ) { // 注意 while 处理多个 case b=a; int *r=bin(b); for(int i=0;i<8;i++){ cout << *(r+i) ; *(r+i)=0; } cout<<"\n"; } }