#C439. Rock Stacks Counting
Rock Stacks Counting
Rock Stacks Counting
Suzuki has a storeroom full of rock stacks. Each rock stack is represented by a character in a string. Your task is to count the number of rocks in each stack type and output a dictionary where each key is a rock type (character) and its corresponding value is the count.
The output dictionary must be formatted as follows:
- The dictionary starts with a left brace
{
and ends with a right brace}
. - Each key-value pair is formatted as
'key': value
(note the single quotes around the key). - Pairs are separated by a comma and a space.
- The ordering of keys must be the same as the order in which they first appear in the input string.
For example, if the input is aabccccd
, then the output should be {'a': 2, 'b': 1, 'c': 4, 'd': 1}
.
Note: If the input string is empty, output an empty dictionary: {}
.
The mathematical representation of the counting operation can be written in \( \LaTeX \) as:
\[ \text{count}(x) = \sum_{i=1}^{n} \mathbb{1}_{\{s_i = x\}}, \quad \forall x \in \text{set}(s) \]
inputFormat
The input consists of a single line string s representing the rock stacks. The string may be empty.
Input Format:
s
outputFormat
Output a single line containing the dictionary representation of the rock counts. The dictionary should be formatted in the style shown in the description with keys in the order of their first appearance.
Output Format:
{'a': count_a, 'b': count_b, ...}## sample
aabccccd
{'a': 2, 'b': 1, 'c': 4, 'd': 1}