Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
136463 严鑫亮 字符串的奇偶性 C++ Accepted 1 MS 276 KB 720 2025-11-15 10:26:32

Tests(1/1):


Code:

#include <iostream> #include <cstring> using namespace std; int main() { while(1) { string s; int count1 = 0; int count2 = 0; cin >> s; if(s == "#")break; char finlly = s.back(); string s2 = s.substr(0,s.size()-1); for(int i = 0; i < s2.size();i++) { if(s2[i] == '1') { count1++; } } char replace_char; if(finlly == 'e') { replace_char = count1 % 2 == 0 ? '0':'1'; }else { replace_char = count1 % 2 == 0 ? '1':'0'; } cout <<s2<<replace_char << endl; } }