문제
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의 갯수를 세주자.
소스코드
출처
'PS > Baekjoon Online Judge' 카테고리의 다른 글
[백준 05497] XOR 1 [TEXT] (0) | 2024.06.24 |
---|---|
[백준 05365] Decoder [Python] (0) | 2024.06.24 |
[백준 04153] 직각삼각형 [C/C++] (2) | 2024.06.21 |
[백준 20737] Sanic [Python] (0) | 2024.06.21 |
[백준 14467] 소가 길을 건너간 이유 1 [Python] (1) | 2024.06.19 |