#K85692. Book Filter and CSV Formatter
Book Filter and CSV Formatter
Book Filter and CSV Formatter
You are given an integer (page_limit) and a list of (n) books. Each book has a title, an author, and a number of pages. Your task is twofold:
-
Filter out all books whose number of pages is strictly greater than (page_limit), and then sort these filtered books in descending order based on the number of pages.
-
Given a target author (provided as input after the book list), output in CSV format all books written by that author. The CSV output should start with a header line "title,pages", followed by a line for each book (in the same order as they appear in the input).
The final output should first list the filtered and sorted books (one book per line, with the format: title, author, pages), then an empty line, and finally the CSV formatted data for the target author.
inputFormat
Standard input (stdin) is used to provide input data in the following format:
- The first line contains an integer (page_limit).
- The second line contains an integer (n), the number of books.
- The next (n) lines each contain the details of one book in the format: (title) (author) (pages). (title) and (author) are strings without spaces, and (pages) is an integer.
- The last line contains the target author name for the CSV output.
outputFormat
Standard output (stdout) should be produced as follows:
- First, print the filtered list of books (books having pages > (page_limit)), sorted in descending order based on pages. Each book is printed on a separate line in the format:
title author pages
. - Then, print an empty line.
- Finally, print the CSV formatted data for the target author. The first line must be the CSV header:
title,pages
, followed by one line for each book by that author (in the same order as they appear in the input) with fields separated by a comma.## sample
100
4
BookA Author1 150
BookB Author1 250
BookC Author2 50
BookD Author2 350
Author1
BookD Author2 350
BookB Author1 250
BookA Author1 150
title,pages
BookA,150
BookB,250
</p>