题解 | #奇偶校验#
奇偶校验
https://www.nowcoder.com/practice/729d11d043d8448e83befa1410b694fe
#include <bitset>
#include <iostream>
using namespace std;
int main() {
string s;
while (cin >> s) { // 注意 while 处理多个 case
for (auto iter = s.begin(); iter != s.end(); ++iter) {
bitset<8> bs(*iter);
auto c = bs.count();
bs[7] = (c % 2 != 1);
cout << bs << endl;
}
}
}
// 64 位输出请用 printf("%lld")
使用c++的bitset处理二进制数问题可以有效简化代码
