DWITE Online Computer Programming Contest

Binary Test Strings 2

December 2009
Problem 3

The last round’s Q3 had quite a few problems, so I’m redoing the question.

The input file DATA3.txt will contain 5 lines, each being a binary string of length 1 to 8 – a pattern that should not appear in binary strings in the generated set.

That is, if the input is “1”, then the only valid output string is “00000000” (any other binary string of size 8 will contain “1”). A pattern “111111” blocks out:

The output file OUT3.txt will contain 5 lines, each being a sum of 1s present in the filtered sets.

Notes regarding the samples: “1” filters out everything but “00000000”, which has no 1s, and so the sum is 0. “0” filters out everything but “11111111”, which has eight 1s, so the sum is 8. The only pattern that “00000000” filters out is itself, which doesn’t contribute to the sum anyway. All of the 8-bit binary strings: 1, 10, 11, ..., 11111110, 11111111 contain 1024 1s. Yes, I’ve counted them.

Sample Input:
1
0
11
00
00000000
Sample Output:
0
8
130
310
1024