#K49647. Minimum Operations to Convert Binary Strings to All Ones
Minimum Operations to Convert Binary Strings to All Ones
Minimum Operations to Convert Binary Strings to All Ones
You are given a collection of binary strings. For each binary string, your task is to determine the minimum number of operations required to convert it into a string that consists solely of the character '1'.
An operation is defined as flipping the bits (changing '0' to '1' or vice versa) in the entire string. However, a careful observation shows that you only need to perform an operation if the string is not already all '1's. In fact, if a string contains any '0', one operation will always suffice to turn it into all '1's regardless of its pattern.
Note:
- If the string is already composed entirely of '1's, then the answer is 0.
- If the string contains at least one '0', the answer is 1.
You must process multiple test cases. The input will first provide the number of test cases, followed by each binary string on a new line.
inputFormat
The first line of input contains an integer t (1 ≤ t ≤ 105) — the number of test cases. Each of the following t lines contains a binary string s consisting of characters '0' and '1'.
outputFormat
For each test case, output a single integer on a new line representing the minimum number of operations required to convert the given string to a string of all '1's.
## sample4
0110
1001
1111
0000
1
1
0
1
</p>