#C156. Book Library Search

    ID: 44778 Type: Default 1000ms 256MiB

Book Library Search

You are given a library system that supports adding new book titles and searching for them by a provided keyword. The search must be case-insensitive and should return all book titles that contain the given keyword as a substring. The order in which the books are added must be preserved in the search results.

For example, if you add the titles "Learning Python", "Python CookBook", "Effective Java", and "JavaScript: The Good Parts", then a search with keyword "Python" should output "Learning Python,Python CookBook" and a search with keyword "Java" should output "Effective Java,JavaScript: The Good Parts". If no books match the search criterion, print an empty line.

This problem challenges your ability to process sequential commands and perform case-insensitive substring matching.

inputFormat

The input is given via standard input. The first line contains an integer T (T ≥ 1) representing the number of commands. Each of the following T lines contains a command. A command is in one of the two formats:

  1. "ADD <book_title>" which adds a book title to the library.
  2. "SEARCH " which searches for all book titles containing the given keyword (case-insensitive) and prints the results.

For each SEARCH command, output the matching titles separated by commas in the order they were added. If no title matches, output an empty line.

outputFormat

For each SEARCH command, output a single line containing a comma-separated list of book titles that contain the keyword (case-insensitive). If no books match, output an empty line.## sample

7
ADD Learning Python
ADD Python CookBook
ADD Effective Java
ADD JavaScript: The Good Parts
SEARCH Python
SEARCH Java
SEARCH C++
Learning Python,Python CookBook

Effective Java,JavaScript: The Good Parts

</p>