Run ID:151303
提交时间:2026-04-11 16:30:27
#include <iostream> #include <string> using namespace std; int main() { string s; while (cin >> s) { if (s == "#") break; // 最后一位是 e/o,前面是比特串 char req = s.back(); string bit = s.substr(0, s.size() - 1); // 统计 1 的个数 int cnt = 0; for (char c : bit) { if (c == '1') cnt++; } char add; if (req == 'e') { // 偶性:1 总数要偶数 add = (cnt % 2 == 0) ? '0' : '1'; } else { // 奇性:1 总数要奇数 add = (cnt % 2 == 1) ? '0' : '1'; } // 输出结果 cout << bit + add << endl; } return 0; }