#C3847. Maximizing Ones in Binary Subsequences

    ID: 47319 Type: Default 1000ms 256MiB

Maximizing Ones in Binary Subsequences

Maximizing Ones in Binary Subsequences

You are given a list of binary strings. For each string, your task is to determine the maximum number of ones ('1's) that can be obtained by selecting a subsequence of the given binary string. Note that a subsequence is a sequence that can be derived from the string by deleting some or no elements without changing the order of the remaining characters. Since removing zeros can only increase the density of ones, the answer for each string is simply the total count of '1's in that string.

Example:

  • For the binary string "110101", the maximum number of ones is 4.
  • For the binary string "10101", the answer is 3.

This problem tests your ability to process input from standard input and produce output to standard output. Make sure your program can handle multiple test cases as specified in the input format.

inputFormat

The input is provided via stdin and has the following format:

T
S1
S2
...
ST

Where:

  • T is an integer denoting the number of binary strings.
  • Each Si is a binary string consisting only of characters '0' and '1'.

outputFormat

For each binary string in the input, output a single line containing an integer which is the maximum number of '1's that can be obtained in any subsequence of that string. The output should be written to stdout.

result1
result2
...
resultT
## sample
1
11111
5

</p>