Tokitsukaze and Good 01-String (easy version) (Codeforces 1678B1)
Tags: Implement, implementation

This is the easy version of the problem. The only difference between the two versions is that the harder version asks additionally for a minimum number of subsegments.Tokitsukaze has a binary string $$$s$$$ of length $$$n$$$, consisting only of zeros and ones, $$$n$$$ is even.Now Tokitsukaze divides $$$s$$$ into the minimum number of contiguous subsegments, and for each subsegment, all bits in each subsegment are the same. After that, $$$s$$$ is considered good if the lengths of all subsegments are even.For example, if $$$s$$$ is "11001111", it will be divided into "11", "00" and "1111". Their lengths are $$$2$$$, $$$2$$$, $$$4$$$ respectively, which are all even numbers, so "11001111" is good. Another example, if $$$s$$$ is "1110011000", it will be divided into "111", "00", "11" and "000", and their lengths are $$$3$$$, $$$2$$$, $$$2$$$, $$$3$$$. Obviously, "1110011000" is not good.Tokitsukaze wants to make $$$s$$$ good by changing the values of some positions in $$$s$$$. Specifically, she can perform the operation any number of times: change the value of $$$s_i$$$ to '0' or '1'($$$1 \leq i \leq n$$$). Can you tell her the minimum number of operations to make $$$s$$$ good?

Input: The first contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 10\,000$$$) — the number of test cases.For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 2 \cdot 10^5$$$) — the length of $$$s$$$, it is guaranteed that $$$n$$$ is even.The second line contains a binary string $$$s$$$ of length $$$n$$$, consisting only of zeros and ones.It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

Output: For each test case, print a single line with one integer — the minimum number of operations to make $$$s$$$ good.

Note: In the first test case, one of the ways to make $$$s$$$ good is the following.Change $$$s_3$$$, $$$s_6$$$ and $$$s_7$$$ to '0', after that $$$s$$$ becomes "1100000000", it can be divided into "11" and "00000000", which lengths are $$$2$$$ and $$$8$$$ respectively. There are other ways to operate $$$3$$$ times to make $$$s$$$ good, such as "1111110000", "1100001100", "1111001100".In the second, third and fourth test cases, $$$s$$$ is good initially, so no operation is required.

Sample Inputs:
5
10
1110011000
8
11001111
2
00
2
11
6
100110

Sample Outputs:
3
0
0
0
3

Solution (Python):
import sys
import math
input = sys.stdin.readline
for _ in range(int(input())):
    n = int(input())
    s = input()
    res1 = 0
    for i in range(0, n - 1, 2):
        if s[i] != s[i + 1]:
            res1 += 1
    print(res1)

Solution (Python):
from collections import defaultdict
import math as m
import sys
input = sys.stdin.readline

def cin2int():
    temp = input().split()
    return (int(temp[0]), int(temp[1]))

def cin3int():
    temp = input().split()
    return (int(temp[0]), int(temp[1]), int(temp[2]))

def cinarr():
    temp = input().split()
    return [int(x) for x in temp]

def solve():
    n = int(input())
    a = input()
    res = 0
    for i in range(1, n, 2):
        if a[i - 1] != a[i]:
            res += 1
    return res
if __name__ == '__main__':
    for case in range(int(input())):
        print(solve())

Solution (Python):
n = int(input())
answer = []
for i in range(n):
    length = int(input())
    bstr = input()
    counter = 0
    for elem in range(0, length, 2):
        if bstr[elem] != bstr[elem + 1]:
            counter += 1
    answer.append(counter)
for ans in answer:
    print(ans)