#C12492. Character Frequency Counter
Character Frequency Counter
Character Frequency Counter
Given a string S, your task is to count the number of occurrences of each unique character in the string and output the result as a dictionary. The dictionary should display each character as a key and its frequency as the corresponding value. The order of keys should be the same as the order in which they first appear in the input.
For example, given the input HelloWorld
, the output should be {'H': 1, 'e': 1, 'l': 3, 'o': 2, 'W': 1, 'r': 1, 'd': 1}
.
Note: Consider all characters, including spaces and digits. The frequency count should be case-sensitive.
Mathematically, if we denote the input string as \(S = s_1s_2\cdots s_n\), then for each unique character \(c\) in \(S\), let \(f(c)\) be its frequency. You are required to compute \(f(c)\) for every \(c\) in \(S\).
inputFormat
The input consists of a single line containing the string S. The string may contain letters, digits, spaces, and punctuation.
Input Format: stdin
outputFormat
The output should be a dictionary (in the format shown in the examples) where each key is a character from the input and the corresponding value is the frequency of that character in the input string.
Output Format: stdout
HelloWorld
{'H': 1, 'e': 1, 'l': 3, 'o': 2, 'W': 1, 'r': 1, 'd': 1}