#C3323. Book Purchase Categorization
Book Purchase Categorization
Book Purchase Categorization
You are given a list of book purchases. Each purchase is a string that represents the type of book bought. The five possible book types are:
fiction
non-fiction
comic
educational
magazine
Your task is to count how many times each type appears in the given list. If any type is not purchased, its count should be 0
.
The input is provided via standard input (stdin) in the following format:
n book1 book2 ... bookn
where n
is the number of purchased books, and the following line contains n
space-separated strings representing the book types.
The output should be printed to standard output (stdout) as a JSON object with exactly the following keys (in this order): fiction
, non-fiction
, comic
, educational
, magazine
. Each key maps to the respective count.
For example: if the input is:
7 fiction comic non-fiction educational comic fiction magazine
then the output should be:
{"fiction": 2, "non-fiction": 1, "comic": 2, "educational": 1, "magazine": 1}
Note that you must use \( \LaTeX \) format for any formulas. In this problem, if needed, you could denote the count for a type \( t \) as \( count(t) \) and the expected result is:
{\"fiction\": count(\"fiction\"), \"non-fiction\": count(\"non-fiction\"), \"comic\": count(\"comic\"), \"educational\": count(\"educational\"), \"magazine\": count(\"magazine\")}
inputFormat
The first line of the input contains an integer \( n \) (where \( n \ge 0 \)), the number of book purchases. The next line contains \( n \) space-separated strings, each representing the type of a purchased book. The possible book types are: 'fiction', 'non-fiction', 'comic', 'educational', and 'magazine'.
outputFormat
Output a JSON object to standard output. The object must contain exactly 5 keys in the following order: 'fiction', 'non-fiction', 'comic', 'educational', and 'magazine'. The value for each key is the count of that book type in the input.
## sample7
fiction comic non-fiction educational comic fiction magazine
{"fiction": 2, "non-fiction": 1, "comic": 2, "educational": 1, "magazine": 1}