题解 | #奇偶校验#
奇偶校验
https://www.nowcoder.com/practice/729d11d043d8448e83befa1410b694fe
#include <bitset> #include <iostream> using namespace std; int main() { char s; while (cin >> s) { bitset<8> bs(s); auto c = bs.count(); bs[7] = (c % 2 != 1); cout << bs << endl; } return 0; }
(吸取了评论区大佬的编程思路)