#C12185. Count String Occurrences
Count String Occurrences
Count String Occurrences
You are given a list of strings. Your task is to count how many times each unique string appears in the list and output the result in JSON format. The input starts with an integer n (where n ≥ 0), representing the number of strings, followed by n lines, each containing one string.
The frequency of a string \( s \) is defined as:
\( f(s) = \text{number of occurrences of } s \)
If the list is empty, output an empty JSON object: {}
.
Example:
Input: 6 apple banana apple orange banana apple</p>Output: {"apple": 3, "banana": 2, "orange": 1}
inputFormat
The first line of input contains an integer n (the number of strings). The following n lines each contain a single string.
outputFormat
Output a JSON object where each key is a unique string from the input and its corresponding value is the number of times it appears. The keys in the output should be sorted in lexicographical order.
## sample6
apple
banana
apple
orange
banana
apple
{"apple": 3, "banana": 2, "orange": 1}