#K42977. Character Frequency Counting
Character Frequency Counting
Character Frequency Counting
Given a string s
, count the number of occurrences of each character in a case-insensitive manner. First, convert all alphabetic characters to lowercase. Then, count each character while preserving the order of their first appearance in the string.
The result should be printed as a JSON object where keys are characters (in double quotes) and values are their corresponding counts. For example, if the input is Programming
, the output should be:
{"p":1,"r":2,"o":1,"g":2,"a":1,"m":2,"i":1,"n":1}
You can use the formula \(lowercase = \text{toLowerCase}(character)\) to convert letters to lowercase if needed.
inputFormat
Input consists of a single line containing the string s
. The string may include letters, digits, and other characters.
outputFormat
Output the character frequency dictionary in JSON format. The dictionary should have keys in the order of their first appearance in the string with each key enclosed in double quotes and mapped to its count without spaces. For an empty input string, output an empty JSON object: {}
.
Programming
{"p":1,"r":2,"o":1,"g":2,"a":1,"m":2,"i":1,"n":1}