Problem C
Even Parity Bit
Problem Description:
A Parity bit is an extra bit that is
attached to a code that is being transferred from one location to another. The
parity bit is made either 0 or 1, depending on the number of 1s that are
contained in the code group. There are two different methods: 1. Even-Parity
Method 11. Odd-Parity Method. In the Even-Parity
method, the value of parity bit is chosen so that the total number of 1s in
the code group (including the parity bit) is an even number. For example,
suppose that the group is 1000011. The code group has three 1s. Therefore, we
will add a parity bit of 1 to make the total number of 1s an even number. The
new code group including the parity bit, thus becomes: 1
1 0 0 0 0 1 1. If the code group contains an even number of 1s to being
with, the parity bit is given a value of 0. For example, if the code group were
1000001, the assigned parity bit would be 0, so that the new code, including
the parity bit, would be 0 1 0 0 0 0 0 1.
As a programmer
you are invited to design a program that will take a Binary Number as input and
print the Binary Number including Even Parity bit as a output.
Input:
The first line
of input will contain a number N(1<=N<=10), that will denote the maximum
number of bit for the binary number that will be used for parity bit. The
second line will contain binary number where each bit is separated by blank
space.
Output:
You will have to
output the Binary Number including Parity bit in one line for every test case.
Sample Input
|
Sample Output
|
5
0 1 1 0 1
6
0 1 1 0 1 1
|
1 0 1 1 0 1
0 0 1 1 0 1 1
|
Solve this problem with
ReplyDelete0<=N<=1000