- 题目描述:
-
输入一个字符串,然后对每个字符进行奇校验,最后输出校验后的二进制数(如'3’,输出:10110011)。
- 输入:
-
输入包括一个字符串,字符串长度不超过100。
- 输出:
-
可能有多组测试数据,对于每组数据,
对于字符串中的每一个字符,输出按题目进行奇偶校验后的数,每个字符校验的结果占一行。
- 样例输入:
-
3 3a
- 样例输出:
-
10110011 10110011 01100001
#include<iostream> #include<string> #include<bitset> using namespace std; int main() { string s; while(cin >> s) { for(string::size_type ix=0; ix!=s.size(); ix++) { bitset<8> bits(s[ix]); if(bits.count()%2==0) { bits.flip(7); } cout<< bits << endl; } } return 0; }