#K49232. Book Categorization Challenge
Book Categorization Challenge
Book Categorization Challenge
You are given a collection of books. Each book is described by a JSON object with three properties: title
(a string), author
(a string), and pages
(an integer representing the number of pages in the book). Your task is to categorize these books into three categories based on the number of pages.
The categories are defined as follows:
- Short: books with \(pages < 100\).
- Medium: books with \(100 \le pages \le 300\).
- Long: books with \(pages > 300\).
You need to output a JSON object with three keys: short
, medium
, and long
. Each key should have an array of book titles that belong to that category.
inputFormat
The input is provided via stdin as a single line containing a valid JSON array. Each element of the array is an object representing a book with the following properties:
title
: a stringauthor
: a stringpages
: an integer
For example:
[{"title": "Book A", "author": "Author A", "pages": 50}, {"title": "Book B", "author": "Author B", "pages": 150}]
outputFormat
The output should be printed to stdout as a JSON object with three keys: short
, medium
, and long
. Each key maps to an array containing the titles (strings) of the books that fall under that category.
For example:
{"short": ["Book A"], "medium": ["Book B"], "long": []}## sample
[{"title": "Book A", "author": "Author A", "pages": 50}, {"title": "Book B", "author": "Author B", "pages": 150}, {"title": "Book C", "author": "Author C", "pages": 350}]
{"short":["Book A"],"medium":["Book B"],"long":["Book C"]}