Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
26820 | 唐心 | 字符串的奇偶性 | C++ | Accepted | 3 MS | 716 KB | 642 | 2022-05-24 17:04:26 |
#include <iostream> #include <cstdlib> #include <cstring> using namespace std; int main() { int i,j,num,n=0; char str[50] = {0}; while(str[0]!='#') { n=0; cin >>str; num = strlen(str); for(i = 0; i < num;i++) { if(str[i] == '1') n++; } if(n%2==0&&str[num-1]=='e') { str[num-1]='0'; cout<<str<<endl; } else if(n%2==0&&str[num-1]=='o') { str[num-1]='1'; cout<<str<<endl; } else if(n%2!=0&&str[num-1]=='e') { str[num-1]='1'; cout<<str<<endl; } else if(n%2!=0&&str[num-1]=='o') { str[num-1]='0'; cout<<str<<endl; } } return 0; }