Parity
Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 2646 accepted Submission (s): 2043
Problem Description A bit string has odd parity if the number of 1 ' s is odd. A bit string has even parity if the number of 1 ' s is even. The "Zero is considered" to "is" even number, so a bit string with No 1 ' s has even parity. The number of
0 ' s does not affect the parity of a bit string.
Input the input consists of one or more strings, each on a line by itself, followed by a line containing only "#" that Sig Nals the end of the input. Each string contains 1–31 bits followed by either a lowercase letter ' e ' or a lowercase letter ' o '.
Output each line of output must look just like the corresponding line of input, except which the letter at the end is Repla CED by the correct bit so this entire bit string has even parity (if the letter is ' e ') or odd parity (if the letter Was ' O ').
Sample Input
101e 010010o 1e 000e 110100101o #
Sample Output
1010 0100101 11 0000 1101001010
Source 2008 Mid-Central USA
Recommend Zty | We have carefully selected several similar problems for you:2701 2702 2703 2707 2706
The difficulty of the topic lies in. English. If you can't read the problem, you won't be able to get enough water. 囧 The general meaning of the topic is very simple. The former length-1 bits are output as usual. If the last one is ' e ' you want to make it into a even (even) form, if it's an ' o ' you have to make it into a odd (odd) Form. You may still feel puzzled ... That is your English is not good. Look at the problem again. Look up the dictionary. I believe you will soon be enlightened.
Import java.io.*;
Import java.util.*;
public class Main
{public
static void Main (string[] args)
{
//TODO auto-generated method stub
Scanner input = new Scanner (system.in);
while (Input.hasnext ())
{
String str=input.nextline ();
if (Str.equals ("#")) break;
Char A[]=str.tochararray ();
int sum=0;
for (int i=0;i<a.length-1;i++)
{
sum+=a[i]-' 0 ';
System.out.print (A[i]);
if (a[a.length-1]== ' O ' &&sum%2==0)
System.out.println ("1");
if (a[a.length-1]== ' O ' &&sum%2==1)
System.out.println ("0");
if (a[a.length-1]== ' e ' &&sum%2==0)
System.out.println ("0");
if (a[a.length-1]== ' e ' &&sum%2==1)
System.out.println ("1");}}