#C193. Books Filtering

    ID: 45189 Type: Default 1000ms 256MiB

Books Filtering

Books Filtering

You are given a list of books. Each book is described by its title, author, and year of publication. Your task is to filter out and output the books that meet all of the following criteria:

  • The book's title contains a given title keyword (case-insensitive).
  • The book's author name contains a given author keyword (case-insensitive).
  • The publication year of the book lies within a given range, i.e. between \(start\_year\) and \(end\_year\) (both inclusive).

The input is read from standard input (stdin) and the output should be printed to standard output (stdout). The output must be a JSON-formatted list of book objects that satisfy the criteria. Each book object must contain the keys title, author, and year.

Note: When comparing strings, the search must be performed in a case-insensitive manner. In addition, the year criteria is defined as follows:

[ start_year \leq year \leq end_year ]

inputFormat

The input is provided in the following format from stdin:

  • The first line contains an integer \(n\) representing the number of books.
  • Each of the next \(n\) lines contains a book's record in the format:
    title, author, year
    Note that year is an integer.
  • The last line contains the search criteria in the format:
    title_keyword, author_keyword, start_year, end_year
    Here, start_year and end_year are integers.

outputFormat

The output should be a single JSON-formatted list written to stdout. Each element in the list is a book object with keys title, author, and year. The order of the output list should match the order of the books provided in the input that satisfy the filtering criteria.## sample

4
Python Programming, John Doe, 2015
Learning JavaScript, Jane Doe, 2018
Advanced Python, John Doe, 2020
JavaScript for Beginners, James Smith, 2021
Python, Doe, 2010, 2021
[{"title": "Python Programming", "author": "John Doe", "year": 2015}, {"title": "Advanced Python", "author": "John Doe", "year": 2020}]

</p>