#K45802. Minimum Flip-Flop Operations

    ID: 27834 Type: Default 1000ms 256MiB

Minimum Flip-Flop Operations

Minimum Flip-Flop Operations

You are given a list of binary strings. For each string, you must determine the minimum number of flip-flop operations required to transform it into a string where all the '1's appear before any '0's. A flip‐flop operation is defined as converting a contiguous occurrence of the substring 10 into 01. In other words, you need to count the minimum number of disjoint 10 patterns that exist in the string. This can be formally described by identifying each occurrence of the pattern 10 in the string. Note that consecutive overlapping occurrences should be treated as a single operation. The formula for the number of operations for a given binary string s can be derived as:

\( \text{operations}(s) = \sum_{i=0}^{|s|-2} \mathbf{1}_{\{s[i]=1 \text{ and } s[i+1]=0\}} \)

Input/Output details: The program will receive multiple binary strings and must output the corresponding minimum number of operations for each string in the order received.

inputFormat

The input is given from standard input and is formatted as follows:

  1. The first line contains an integer T representing the number of binary strings.
  2. The following T lines each contain a binary string. Note that a line can be empty, representing an empty string.

outputFormat

For each input binary string, output the minimum number of flip-flop operations required to have all '1's come before all '0's. The answers for all test cases should be printed on a single line separated by a space.

## sample
3
110
11001
10010
1 1 2