PAT (Advanced Level) Practise 1022 Digital Library (30)

来源:互联网 发布:java实现扫码支付 编辑:程序博客网 时间:2024/05/20 03:07

1022. Digital Library (30)

时间限制
1000 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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 (<=10000) 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


题意:给出若干条书籍信息:按照书名、作者、关键字、出版商、出版年份的格式列出;再给出若干条检索记录,这些检索记录是围绕书名、作者、关键字、出版社以及年份,来按顺序列出查询的书的ID

解题思路:map+vector即可


#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <algorithm>#include <cmath>#include <map>#include <cmath>#include <set>#include <stack>#include <queue>#include <vector>#include <bitset>#include <functional>using namespace std;#define LL long longconst int INF = 0x3f3f3f3f;int n;vector<string> g[100009];map<string, int> mp[5];char s1[100009], s2[100009], s3[100009];int main(){while (~scanf("%d", &n)){int cnt = 1;for(int i=1;i<=n;i++){scanf("%s", s1);getchar();for (int j = 0; j < 5; j++){gets(s2);if (j == 2){int len = strlen(s2);s2[len++] = ' ', s2[len] = '\0';for (int k = 0, p = 0;k<len ; k++){if (s2[k] == ' '){s3[p] = '\0',p = 0;if (!mp[j][s3]) mp[j][s3] = cnt++;g[mp[j][s3]].push_back(s1);}else s3[p++] = s2[k];}}else{if (!mp[j][s2]) mp[j][s2] = cnt++;g[mp[j][s2]].push_back(s1);}}}scanf("%d", &n);while (n--){scanf("%s ", s1);gets(s2);int k = s1[0] - '1';printf("%s %s\n", s1, s2);if (!mp[k][s2]) printf("Not Found\n");else{k = mp[k][s2];sort(g[k].begin(), g[k].end());for (int i = 0; i < g[k].size(); i++)cout << g[k][i] << endl;}}}return 0;}