PS/Baekjoon Online Judge

[백준 05343] Parity Bit [Python]

kimyoungrok 2024. 6. 23. 02:56
728x90

문제

A parity bit, or check bit, is a bit that is added to the end of a sequence of bits for error detection. In telecommunications and computing all data is transformed into a sequence of zeros and ones. For this problem you may assume that all information is coded using 8 bits, with the first 7 bits used for data and the last bit used as the parity bit. The parity bit is set to one if the number of ones in the preceding 7 bits is odd, and the parity bit is set to zero if the number of ones in the preceding 7 bits is even.

The parity bit can be used to determine if the data was transmitted incorrectly. If the parity bit is incorrect (does not match the parity of the previous 7 bits), then a parity error occurred. Your job is to read lines of data and determine the number of parity errors on each line.

입력

The first line will be a positive integer indicating the number of lines of data transmitted. Each line of data will be a sequence of zeros and ones and the length of the line will be a multiple of 8 and no longer than 64.

출력

For each data transmission line print the number of parity errors found in the data transmission.


풀이

각 패리티 비트를 입력받아 오류 수를 출력하면 되는 문제다.

1의 갯수가 홀수인 경우에만 오류다.

패리티 비트는 8~64개로 주어지니 입력에 따라서 구간별로 1의 갯수를 세주자.


소스코드

보기


출처

https://www.acmicpc.net/problem/5343

728x90