#K51677. Library Queries
Library Queries
Library Queries
You are given a collection of books. Each book has a title, an author, and a number of pages. Your task is to answer several queries regarding these books.
The queries are defined as follows:
- Query 1: Find the book with the maximum number of pages and print its title and author.
- Query 2: Find the book with the minimum number of pages and print its title and author.
- Query 3: Calculate the average number of pages of all books, using integer division. That is, compute \(\lfloor \frac{\text{sum of pages}}{n} \rfloor\), where \(n\) is the number of books.
Input is provided via standard input and output must be written to standard output.
inputFormat
The input format is as follows:
- An integer \(n\) representing the number of books.
- Then \(n\) lines follow, each containing three values: the
title
(a string), theauthor
(a string), and thepages
(an integer) for that book. The values are separated by spaces. - An integer \(q\) representing the number of queries.
- A single line with \(q\) integers separated by spaces, where each integer is either 1, 2, or 3 corresponding to the query types described above.
Read from standard input.
outputFormat
For each query, output the result on a new line:
- For Query 1, print the title and author of the book with the maximum pages.
- For Query 2, print the title and author of the book with the minimum pages.
- For Query 3, print the average number of pages (using integer division).
Write the output to standard output.
## sample3
The_Great_Gatsby F_Scott_Fitzgerald 180
1984 George_Orwell 328
To_Kill_a_Mockingbird Harper_Lee 281
3
1 2 3
1984 George_Orwell
The_Great_Gatsby F_Scott_Fitzgerald
263
</p>