counts number of ones at odd and even positions
int odd_1 = 0 , even_1 = 0 ; int n = st . length ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( i % 2 == 0 ) { if ( st [ i ] == '1' ) even_1 ++ ; else even_0 ++ ; } else { if ( st [ i ] == '1' ) odd_1 ++ ; else odd_0 ++ ; } }