A Digital Library contains millions of books, stored according to their titles, authors, key words of their abstracts, publishers, and published years. Each book is assigned an unique 7-digit number as its ID. Given any query from a reader, you are supposed to output the resulting books, sorted in increasing order of their ID's.
Input Specification:
Each input file contains one test case. For each case, the first line contains a positive integer N (≤104) which is the total number of books. Then N blocks follow, each contains the information of a book in 6 lines:
- Line #1: the 7-digit ID number;
- Line #2: the book title -- a string of no more than 80 characters;
- Line #3: the author -- a string of no more than 80 characters;
- Line #4: the key words -- each word is a string of no more than 10 characters without any white space, and the keywords are separated by exactly one space;
- Line #5: the publisher -- a string of no more than 80 characters;
- Line #6: the published year -- a 4-digit number which is in the range [1000, 3000].
It is assumed that each book belongs to one author only, and contains no more than 5 key words; there are no more than 1000 distinct key words in total; and there are no more than 1000 distinct publishers.
After the book information, there is a line containing a positive integer M (≤1000) which is the number of user's search queries. Then M lines follow, each in one of the formats shown below:
- 1: a book title
- 2: name of an author
- 3: a key word
- 4: name of a publisher
- 5: a 4-digit number representing the year
Output Specification:
For each query, first print the original query in a line, then output the resulting book ID's in increasing order, each occupying a line. If no book is found, print Not Found
instead.
Sample Input:
31111111The Testing BookYue Chentest code debug sort keywordsZUCS Print20113333333Another Testing BookYue Chentest code sort keywordsZUCS Print220122222222The Testing BookCYLLkeywords debug bookZUCS Print2201161: The Testing Book2: Yue Chen3: keywords4: ZUCS Print5: 20113: blablabla
Sample Output:
1: The Testing Book111111122222222: Yue Chen111111133333333: keywords1111111222222233333334: ZUCS Print11111115: 2011111111122222223: blablablaNot Found
1 package pattest; 2 3 import java.io.BufferedReader; 4 import java.io.IOException; 5 import java.io.InputStreamReader; 6 import java.util.HashMap; 7 import java.util.TreeSet; 8 9 /**10 * @Auther: Xingzheng Wang11 * @Date: 2019/2/27 23:1712 * @Description: pattest13 * @Version: 1.014 */15 public class PAT1022 {16 static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));17 18 static class Library {19 HashMap>[] allMaps = new HashMap[5];20 21 Library() throws IOException {22 for (int i = 0; i < 5; i++) {23 HashMap > map = new HashMap<>(1000, 1);24 allMaps[i] = map;25 }26 int record_size = Integer.valueOf(reader.readLine());27 for (int i = 0; i < record_size; i++) {28 String id = reader.readLine();29 for (int j = 0; j < allMaps.length; j++) {30 HashMap > map = allMaps[j];31 if (j == 2) {32 String[] keys = reader.readLine().split(" ");33 for (String key : keys) {34 putValue(map, key, id);35 }36 } else {37 String key = reader.readLine();38 putValue(map, key, id);39 }40 }41 }42 }43 44 private void putValue(HashMap > map, String key, String id) {45 TreeSet integers = map.computeIfAbsent(key, k -> new TreeSet<>());46 integers.add(id);47 }48 49 TreeSet query(int id, String queryString) {50 HashMap > allMap = allMaps[id - 1];51 TreeSet integers = allMap.get(queryString);52 return integers;53 }54 }55 56 public static void main(String[] args) throws IOException {57 Library library = new Library();58 int query_size = Integer.valueOf(reader.readLine());59 for (int i = 0; i < query_size; i++) {60 String line = reader.readLine();61 System.out.println(line);62 int id = line.charAt(0) - 48;63 String query = line.substring(3);64 TreeSet queryResult = library.query(id, query);65 if (queryResult == null) {66 System.out.println("Not Found");67 } else {68 for (String book_id : queryResult) {69 System.out.println(book_id);70 }71 }72 }73 }74 }