#K2036. Character Frequency Count

    ID: 24647 Type: Default 1000ms 256MiB

Character Frequency Count

Character Frequency Count

Given a string S, your task is to count the frequency of each non-space character, ignoring spaces and treating uppercase and lowercase letters as identical. All characters (including punctuation) other than spaces should be counted. The final result must be output as a JSON object string where the keys (characters) are sorted in ascending order (according to their ASCII values).

Processing Steps:

  • Remove all spaces from the input string.
  • Convert the remaining characters to lowercase.
  • Count the occurrences of each character.
  • Output the result as a JSON object with keys in ascending order. For example, for the input Hello, World!, the output should be:</p> $${\"!\": 1, \",\": 1, \"d\": 1, \"e\": 1, \"h\": 1, \"l\": 3, \"o\": 2, \"r\": 1, \"w\": 1} $$

    Note: The output must strictly adhere to the JSON object format.

    inputFormat

    The input consists of a single line containing a string S.
    The string may include letters, punctuation, and spaces.

    outputFormat

    Output a single JSON object string that represents the frequency count of each character in the modified string (after removing spaces and converting all characters to lowercase). The keys in the JSON object must be sorted in ascending order based on their ASCII values.

    ## sample
    hello
    {"e": 1, "h": 1, "l": 2, "o": 1}