Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
160547 赵乐骏 字符串的奇偶性 C++ Accepted 1 MS 276 KB 525 2026-09-21 21:08:02

Tests(1/1):


Code:

#include <bits/stdc++.h> using namespace std; int main() { string s; while (cin >> s) { if (s == "#") break; int n = s.size(); char f = s[n - 1]; string a = s.substr(0, n - 1); int c = 0; for (int i = 0; i < a.size(); i++) { if (a[i] == '1') c++; } if (f == 'e') { cout << a << (c % 2 == 1 ? '1' : '0') << endl; } else { cout << a << (c % 2 == 1 ? '0' : '1') << endl; } } return 0; }