Last time you helped Orange Cat complete his puzzles. This time, he wants to arrange these puzzles on his shelf.
Each puzzle can be represented by a string composed of digits from 0 to 9. Since the orange cat has a special preference for multiples, he defines a function f(s, x, m) which counts how many substrings of length m in string s representing numbers that are multiples of x.
Now give you n puzzles p1 ~ pn, for each string si, calculate f(si, x1, m), f(si, x2, m), ..., f(si, xk, m) and sort the strings according to the following priority:
Divisibility Rules for numbers 2 through 4 (You may also use alternative methods.):
2: The last digit is even.
3: The sum of all digits is divisible by 3.
4: The last two digits form a number divisible by 4.
The first line contains three positive integers n, m, k.
The second line contains k positive integers x1 ~ xk
The following n lines each contain a string si.
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:
The meaning of k in this problem is:
k = 1: You only need to compare the number of multiples of 2
k = 2: You need to first compare multiples of 2, if equal, then compare multiples of 3
k = 3: Following this pattern, compare in priority order of multiples of 2, 3, and 4