| Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
|---|---|---|---|---|---|---|---|---|
| 158659 | 章泽原 | 字符串的奇偶性 | C++ | Accepted | 1 MS | 272 KB | 833 | 2026-08-22 16:23:21 |
#include <iostream> #include <string> using namespace std; int main() { string s; while (cin >> s) { if (s == "#") break; int cnt1 = 0; // 遍历除最后一位的所有字符,统计1的数量 for (int i = 0; i < s.size() - 1; i++) { if (s[i] == '1') cnt1++; } char op = s.back(); char add; if (op == 'e') // 需要偶数个1 { if (cnt1 % 2 == 0) add = '0'; else add = '1'; } else // 'o' 需要奇数个1 { if (cnt1 % 2 == 1) add = '0'; else add = '1'; } // 截取前面比特串 + add string ans = s.substr(0, s.size()-1) + add; cout << ans << endl; } return 0; }