HDU 2700 Parity

Description

不想讲了

Algorithm

同上

Code

#include <iostream>
#include <string>
using namespace std;
int main()
{
  for (;;)
  {
    string s;
    cin>>s;
    if (s=="#") break;
    int l = s.size();
    char c = s[l-1];
    int n = 0;
    for (int i = 0; i < s.size(); i++)
      if (s[i] == '1') n++;
    n = n % 2;
    if (n == 0)
    {
      if (c == 'o') s[l - 1] = '1'; else s[l - 1] = '0';
    }else
    {
      if (c == 'o') s[l - 1] = '0'; else s[l - 1] = '1';
    }
    cout<<s<<endl;
  }
  return 0;
}

你可能感兴趣的:(HDU 2700 Parity)