#K67627. Counting Gym Clusters
Counting Gym Clusters
Counting Gym Clusters
You are given a binary string S
which represents a sequence of gym equipment statuses, where '1' indicates an active equipment and '0' indicates an inactive one. A gym cluster is defined as one or more consecutive '1's. In other words, if there is a group of one or more consecutive '1's, it is treated as one cluster. For example, in the string "10111"
, there are 2 clusters: one for the single '1' and one for the consecutive group "111
".
Your task is to count the number of gym clusters in each test case.
More formally, if we denote a gym cluster by the regular expression $$1^+$$ (one or more consecutive 1's), then your goal is to count the number of non-overlapping occurrences of this pattern in the string S
.
Input is given via standard input and output should be produced to standard output.
inputFormat
The first line contains an integer T
which indicates the number of test cases. Each of the following T
lines contains a single binary string S
.
outputFormat
For each test case, output a single integer on a new line indicating the number of gym clusters in the given string S
.
3
000
111
10101
0
1
3
</p>