#C10780. Most Frequent Character
Most Frequent Character
Most Frequent Character
You are given a string s
. Your task is to determine the character that appears most frequently in s
. In case of a tie where multiple characters occur the same maximum number of times, you should output the lexicographically smallest character.
Note: The lexicographical order is based on the standard character ordering (i.e. according to their ASCII/Unicode values).
For example:
- If
s = "a"
, the answer isa
. - If
s = "bbbb"
, the answer isb
. - If
s = "abracadabra"
, although both 'a' and 'b' might be candidates, the answer isa
because it is lexicographically smaller.
Solve the problem by reading the input from standard input (stdin
) and writing the result to standard output (stdout
).
The frequency calculation can be mathematically expressed as follows:
$$\text{Let } f(c) = \text{number of occurrences of character } c \text{ in } s. $$$$\text{We want to find } c^* \text{ such that } f(c^*) = \max_{c \in s} f(c) \text{ and for any } d \text{ with } f(d) = f(c^*),\ c^* \leq d. $$inputFormat
The input consists of a single line containing the string s
. The string may include spaces and special characters.
outputFormat
Output a single character which is the most frequent character in the input string. If there is a tie, output the lexicographically smallest character among those with the highest frequency.
## samplea
a