#C321. Book Search
Book Search
Book Search
You are given a search query and an optional author name. Your task is to simulate a book search in a predefined database. The database contains the following two books:
- Harry Potter and the Philosopher's Stone by J.K. Rowling, published in 1997.
- Harry Potter and the Chamber of Secrets by J.K. Rowling, published in 1998.
The program should read input from stdin
and write output to stdout
. If the search query is empty, the program must output an error message. Otherwise, the program should print the details of all books (one per line) in the following format:
title,author,published_year
Note that the search behavior is simulated: regardless of the provided author name, if the query is non-empty, the fixed list of books is returned.
Formally, let \( Q \) be the query string. The program should satisfy: \[ \text{if } Q = \varepsilon, \text{ then output } "Error: The search query must not be empty."; \] Otherwise, output the fixed list of books.
inputFormat
The input consists of two lines:
- The first line contains the search query (a non-empty string).
- The second line contains the author name. This line may be empty; if empty, only the query is used for the search.
All input is read from stdin
.
outputFormat
If the search query is empty, output Error: The search query must not be empty.
(followed by a newline). Otherwise, output the details of the books, one per line, in the following format:
title,author,published_year
The output should be written to stdout
.
Harry Potter
J.K. Rowling
Harry Potter and the Philosopher's Stone,J.K. Rowling,1997
Harry Potter and the Chamber of Secrets,J.K. Rowling,1998
</p>