• A1022. Digital Library (30)


    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:

    3
    1111111
    The Testing Book
    Yue Chen
    test code debug sort keywords
    ZUCS Print
    2011
    3333333
    Another Testing Book
    Yue Chen
    test code sort keywords
    ZUCS Print2
    2012
    2222222
    The Testing Book
    CYLL
    keywords debug book
    ZUCS Print2
    2011
    6
    1: The Testing Book
    2: Yue Chen
    3: keywords
    4: ZUCS Print
    5: 2011
    3: blablabla
    

    Sample Output:

    1: The Testing Book
    1111111
    2222222
    2: Yue Chen
    1111111
    3333333
    3: keywords
    1111111
    2222222
    3333333
    4: ZUCS Print
    1111111
    5: 2011
    1111111
    2222222
    3: blablabla
    Not Found
     1 #include <stdio.h>
     2 #include <stdlib.h>
     3 #include <iostream>
     4 #include <string.h>
     5 
     6 #include <math.h>
     7 #include <algorithm>
     8 #include <vector>
     9 #include <set> 
    10 #include <string>
    11 #include <map> 
    12 using namespace std;
    13 map<string,set<int> >mptitle,mpauthor,mpkey,mppub,mpyear; 
    14 //一个关键字可以对应多个id,所以使用set<int> 
    15 void query(map<string,set<int> >&mp,string &str)
    16 {
    17     if(mp.find(str)==mp.end())printf("Not Found
    ");
    18     else{
    19     for(set<int>::iterator it=mp[str].begin();it!=mp[str].end();it++)//对于已找到的关键字 全部输出 
    20     {
    21         //注意这里使用的是 set<int>,而不是map<string,set<int> 
    22         printf("%07d
    ",*it); 
    23         
    24     }
    25     }
    26 }
    27 
    28  
    29 int main(){
    30     int n,id;
    31     string title,author,key,pub,year;
    32     scanf("%d",&n);
    33     for(int i=0;i<n;i++)
    34     {
    35         scanf("%d",&id);
    36         char c=getchar();//获取换行 
    37         getline(cin,title);
    38         mptitle[title].insert(id);
    39         getline(cin,author);
    40         mpauthor[author].insert(id);
    41         while(cin>>key)
    42         {
    43             mpkey[key].insert(id);
    44             c=getchar();
    45             if(c=='
    ')break;
    46         } 
    47         getline(cin,pub);
    48         mppub[pub].insert(id);
    49         getline(cin,year);
    50         mpyear[year].insert(id); 
    51     } 
    52     string temp;
    53     int m,type;
    54     scanf("%d",&m);
    55     for(int i=0;i<m;i++)
    56     {
    57         scanf("%d: ",&type);//这里格式很重要 空格冒号不能少 
    58         getline(cin,temp);
    59         cout<<type<<": "<<temp<<endl;
    60         if(type==1)query(mptitle,temp);
    61         else if(type==2)query(mpauthor,temp);
    62         else if(type==3)query(mpkey,temp);
    63         else if(type==4)query(mppub,temp);
    64         else query(mpyear,temp);
    65     }
    66     return 0;
    67 }
  • 相关阅读:
    Linux模拟网络延迟、丢包等
    TestLink汉化操作
    onems设备管理系统(TR-069和OMA)
    Installation Guide Ubuntu 16.04
    Configure GenieACS
    Linux下的tar压缩解压缩命令详解
    genieacs Installation on Ubuntu14.04
    Pyqt中富文本编辑器
    安装MongoDB
    到底什么是贝叶斯?
  • 原文地址:https://www.cnblogs.com/ligen/p/4309839.html
Copyright © 2020-2023  润新知