#C3515. Library Catalog Management

    ID: 46951 Type: Default 1000ms 256MiB

Library Catalog Management

Library Catalog Management

You are given a series of commands which simulate the operations of a library catalog system. In this system, each book is added under one or more categories. The commands include:

  • add_book [book_id] [category1] [category2] ...: Add a book with a unique identifier book_id under the specified categories. If the book already exists, ignore the command.
  • remove_book [book_id]: Remove the book with the given book_id from the catalog. If the book does not exist, ignore the command.
  • get_books_by_category [category]: Retrieve a list of book IDs that belong to the given category, sorted in ascending order. If no book exists in that category, output an empty line.
  • The input terminates with a line containing only end.

Your program should process the commands one-by-one. For every get_books_by_category command, output the list of corresponding book IDs separated by a single space, or output an empty line if no books exist under that category.

The final result is printed directly to standard output (stdout).

Note: All formulas in this problem, if any, should be in LaTeX format. For example, the sorting requirement can be stated as: \(\text{sort}(list)\) in ascending order.

inputFormat

The input consists of several lines. Each line represents a command in one of the following formats:

  • add_book <book_id> <category1> <category2> ...
  • remove_book <book_id>
  • get_books_by_category <category>

The input terminates with a line containing only end.

outputFormat

For each get_books_by_category command, output a single line with the list of book IDs (sorted in ascending order) separated by single spaces. If no books match, output an empty line.

## sample
add_book 1 fiction mystery
add_book 2 science fiction
add_book 3 mystery
get_books_by_category fiction
get_books_by_category mystery
remove_book 1
get_books_by_category fiction
get_books_by_category mystery
end
1 2

1 3 2 3

</p>