#C13573. Character Frequency Counter
Character Frequency Counter
Character Frequency Counter
In this problem, you are given a string that may contain letters, digits, and symbols. Your task is to compute the frequency of each character in the string, excluding spaces. The count is case-sensitive; that is, 'A' and 'a' are treated as different characters. You should then output the number of distinct characters (ignoring spaces), followed by each character and its frequency on a separate line. The characters must be printed in ascending order based on their ASCII values.
For instance, if the input is Hello World
, the frequency counts are as follows:
- 'H': 1
- 'W': 1
- 'd': 1
- 'e': 1
- 'l': 3
- 'o': 2
- 'r': 1
7 H 1 W 1 d 1 e 1 l 3 o 2 r 1
Mathematically, for an input string S, ignoring spaces, for every character c, compute its frequency f(c). If K is the number of unique characters, first output K, then output each character c and f(c) in separate lines in increasing order of c (according to ASCII).
inputFormat
The input consists of a single line containing the string whose characters are to be counted.
outputFormat
The first line of the output is an integer K that denotes the number of distinct characters (excluding spaces). Each of the following K lines contains a character and its corresponding frequency separated by a space, listed in ascending order according to the character's ASCII value.## sample
Hello World
7
H 1
W 1
d 1
e 1
l 3
o 2
r 1
</p>