#K61417. Count Ones in a Binary String
Count Ones in a Binary String
Count Ones in a Binary String
You are given a binary string which represents a non-negative integer in its binary form. Your task is to count the number of 1
characters in the string and output the count.
The input will be provided via standard input (stdin), and the result should be printed to standard output (stdout). Ensure your solution handles both small and large inputs efficiently.
For instance, given the input 110101
, the expected output is 4
because there are four 1
characters in the string.
Note: If the string contains no 1
s, output 0
.
inputFormat
The input consists of a single line containing a binary string composed of characters 0
and 1
. The string length can be very large, so consider using efficient input methods.
outputFormat
Output a single integer representing the number of 1
s in the given binary string.
110101
4