#K86552. John's Sorting of Binary Strings
John's Sorting of Binary Strings
John's Sorting of Binary Strings
You are given n binary strings, each of fixed width k. Your task is to sort these binary strings based on their first p bits.
Formally, for each binary string s, consider its prefix of length p (i.e. the first p characters of s). The sorting should be done in lexicographical order of these prefixes. In other words, given two strings \(s_1\) and \(s_2\), they are compared based on the value of \(s_1[0:p]\) and \(s_2[0:p]\), where the notation represents the substring from index 0 (inclusive) to \(p\) (exclusive).
It is guaranteed that all the binary strings are exactly of length k and consist only of the characters '0' and '1'.
inputFormat
The input is read from standard input (stdin) and has the following format:
n k p s1 s2 ... sn
Where:
- n is the number of binary strings.
- k is the fixed width (length) of each binary string.
- p is the number of bits from the beginning of each string that are used to determine the sorting order.
- s1, s2, ..., sn are the binary strings.
outputFormat
Output the sorted list of binary strings to standard output (stdout). Each binary string should be printed on a new line, in the order determined by sorting based on its first p bits.
## sample3 5 3
11010
10100
11100
10100
11010
11100
</p>