• 1022 Digital Library


    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:

    1. 3
    2. 1111111
    3. The Testing Book
    4. Yue Chen
    5. test code debug sort keywords
    6. ZUCS Print
    7. 2011
    8. 3333333
    9. Another Testing Book
    10. Yue Chen
    11. test code sort keywords
    12. ZUCS Print2
    13. 2012
    14. 2222222
    15. The Testing Book
    16. CYLL
    17. keywords debug book
    18. ZUCS Print2
    19. 2011
    20. 6
    21. 1: The Testing Book
    22. 2: Yue Chen
    23. 3: keywords
    24. 4: ZUCS Print
    25. 5: 2011
    26. 3: blablabla

    Sample Output:

    1. 1: The Testing Book
    2. 1111111
    3. 2222222
    4. 2: Yue Chen
    5. 1111111
    6. 3333333
    7. 3: keywords
    8. 1111111
    9. 2222222
    10. 3333333
    11. 4: ZUCS Print
    12. 1111111
    13. 5: 2011
    14. 1111111
    15. 2222222
    16. 3: blablabla
    17. Not Found

    题目大意

    模拟数字图书馆的查询功能。给出N本书的信息,以及M个需要查询的命令,command为 相应的搜索方式,command后面跟着的字符串是搜索的关键词,要求输出满⾜指定搜索书的 id。如果查询结果为NULL,输出Not Found。

    思路

    map模拟即可


    C/C++ 

    1. #include
    2. using namespace std;
    3. map> title,author,keys,publish,year;
    4. void OP(map>& op,const string& key);
    5. int main()
    6. {
    7. string id,s,key;
    8. char ch;
    9. int N,command;
    10. cin >> N;
    11. getchar();
    12. while (N--){
    13. getline(cin,id);
    14. getline(cin,s);
    15. title[s].insert(id);
    16. getline(cin,s);
    17. author[s].insert(id);
    18. key = "";
    19. ch = getchar();
    20. while (ch!='\n'){
    21. if(ch==' '){
    22. keys[key].insert(id);
    23. key = "";
    24. }else key += ch;
    25. ch = getchar();
    26. }
    27. keys[key].insert(id);
    28. getline(cin,s);
    29. publish[s].insert(id);
    30. getline(cin,s);
    31. year[s].insert(id);
    32. }
    33. cin >> N;
    34. while (N--){
    35. scanf("%d: ",&command);
    36. getline(cin,id);
    37. printf("%d: %s\n",command,id.c_str());
    38. switch (command) {
    39. case 1:OP(title,id); break;
    40. case 2:OP(author,id);break;
    41. case 3:OP(keys,id);break;
    42. case 4:OP(publish,id);break;
    43. case 5:OP(year,id);break;
    44. }
    45. }
    46. return 0;
    47. }
    48. void OP(map>& op,const string& key)
    49. {
    50. if(op.find(key)!=op.end()){
    51. for(const string& x:op[key]) cout << x << endl;
    52. }
    53. else puts("Not Found");
    54. }


     

  • 相关阅读:
    sql表的相关操作
    使用电力系统稳定器 (PSS) 和静态 VAR 补偿器 (SVC) 提高瞬态稳定性(Matlab代码实现)
    PHP数组处理$arr1转换为$arr2
    opencv c++ 二值图像、阈值计算方法、全局阈值、自适应阈值
    Linux系统编程(五)——Linux下的多线程
    【考研数据结构代码题】day11-day20
    创建共享内存后,进程结束,共享内存是否会消失?
    LVGL V8.2 嵌入式Linux平台使用tslib实现输入接口(以SSD212为例)
    mybatis学习记录(四)-----MyBatis核心配置文件详解
    拒绝服务攻击工具
  • 原文地址:https://blog.csdn.net/daybreak_alonely/article/details/127701832