#C14125. Sort Strings by Frequency
Sort Strings by Frequency
Sort Strings by Frequency
You are given a list of strings. Your task is to sort the distinct strings according to their frequency of occurrence in descending order. If two strings have the same frequency, sort them in lexicographical ascending order.
Formally, let \( f(s) \) denote the frequency of string \( s \) in the input. You need to output all distinct strings sorted such that for any two strings \( s_1 \) and \( s_2 \), either:
[ f(s_1) > f(s_2) \quad \text{or} \quad \Bigl(f(s_1) = f(s_2) \text{ and } s_1 < s_2\Bigr). ]
Note: The lexicographical order is the standard order based on the ASCII values of characters.
inputFormat
The input is read from standard input (stdin) and has the following format:
n s1 s2 ... sn
Where n
(an integer) denotes the number of strings, and each of the next n
lines contains a string.
outputFormat
Print the distinct strings sorted by the criteria described above, each on its own line, to standard output (stdout).
## sample1
apple
apple
</p>