【例61.3】 图书管理员
You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.
Description
Each book in the library has a book code, which is a positive integer used for quick book retrieval.
Each reader has a request code, which is also a positive integer. If a book's code ends with the reader's request code, then this book is what the reader needs.
Little D has just become the library administrator. She knows all the book codes in the library. She asks you to write a program that, for each reader, finds the book with the smallest code that matches their request. If no matching book exists, output .
Input Format
The first line contains two positive integers and , separated by a space, representing the number of books in the library and the number of readers.
The next lines each contain a positive integer, representing a book code in the library.
The next lines each contain two positive integers, separated by a space. The first integer represents the length of the reader's request code, and the second integer represents the reader's request code.
, , all book codes and request codes are no more than .
Output Format
Output lines, each containing one integer. If there exists a book matching the -th reader's request, output the smallest book code that matches the request on the -th line. Otherwise, output .
Sample
5 5
2123
1123
23
24
24
2 23
3 123
3 124
2 12
2 1223
1123
-1
-1
-1
20250920C班作业(2)
- Status
- Done
- Problem
- 4
- Open Since
- 2025-9-20 0:00
- Deadline
- 2025-10-11 23:59
- Extension
- 24 hour(s)