Last time you helped Orange Cat complete his puzzles. This time, he wants to arrange these puzzles on his shelf. He has a particular fondness for a specific pattern, represented here by a interger x. The number of substring [l, r] in each string that satisfy the following conditions are defined as the preference levels:
When a substring with length m satisfies the above conditions, the preference level increases by 1. In other words, you need to calculate how many substrings with length m in a string satisfy the polynomial conditions above. (For a string "abcdefg", when m = 4, all substrings of length m are: "abcd", "bcde", "cdef", and "defg".)
Please help rearrange these n puzzles (P1 to Pn) by sorting them in descending order based on their preference levels. If two puzzles have the same preference level, maintain their original relative order.
The first line contains five positive integers n, m, k, x, y.
The following n lines each contain a string Pi.
Subtasks
Output n lines, where the i-th line contains a string representing the puzzle placed in the i-th position.
Please remember to print "\n" at the end, and dont print space (" ") at the end of every line
Hint1:
Please implement string swapping in bubble sort using strcpy to avoid TLE (Time Limit Exceeded).
Hint2:
Please be mindful of overflow.
Hint3:
You can use the following template:
for (int i = 0; i + m - 1 < len; i++) {
int l = i, r = i + m - 1, sum = 0;
for (int j = l; j <= r; j++) {
// do something
}
if (sum == x) {
// do something
}
}