zoukankan      html  css  js  c++  java
  • 1022. 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<algorithm>
      3 #include<vector>
      4 #include<stdlib.h>
      5 #include<queue>
      6 #include<set>
      7 #include<string>
      8 #include<map>
      9 #include<iostream>
     10 #include<sstream>
     11 using namespace std;
     12 
     13 map<string,vector<int> > name,author,Keys,publisher;
     14 vector<int> Year[10000];
     15 
     16 void fun(map<string,vector<int> > & mm)
     17 {
     18     for(map<string,vector<int> >::iterator it = mm.begin();it != mm.end();++it)
     19     {
     20         sort(it->second.begin(),it->second.end());
     21     }
     22 }
     23 
     24 
     25 int main()
     26 {
     27     int n,id,year;
     28     string str;
     29     scanf("%d",&n);
     30     for(int i = 1 ;i <= n ;++i)
     31     {
     32         scanf("%d",&id);
     33         getchar();
     34         str.clear();
     35         getline(cin,str);
     36         name[str].push_back(id);
     37         str.clear();
     38         getline(cin,str);
     39         author[str].push_back(id);
     40         str.clear();
     41         getline(cin,str);
     42         stringstream ss;
     43         string keys;
     44         ss << str;
     45         while(ss >> keys)
     46         {
     47             Keys[keys].push_back(id);
     48         }
     49         str.clear();
     50         getline(cin,str);
     51         publisher[str].push_back(id);
     52         scanf("%d",&year);
     53         Year[year].push_back(id);
     54     }
     55     fun(name);
     56     fun(author);
     57     fun(Keys);
     58     fun(publisher);
     59     for(int i =  1000 ; i <= 3000 ;++i)
     60     {
     61         if(!Year[i].empty())
     62         {
     63             sort(Year[i].begin(),Year[i].end());
     64         }
     65     }
     66     int m;
     67     scanf("%d",&m);
     68     for(int i = 0 ;i < m ;++i)
     69     {
     70         int tag;
     71         vector<int> vv;
     72         scanf("%d",&tag);
     73         getchar();
     74         getchar();
     75         str.clear();
     76         if(tag == 1)
     77         {
     78             getline(cin,str);
     79             printf("%d: %s
    ",tag,str.c_str());
     80             vv =  name[str];
     81             
     82         }
     83         else if(tag == 2)
     84         {
     85             getline(cin,str);
     86             printf("%d: %s
    ",tag,str.c_str());
     87             vv =  author[str];
     88         }
     89         else if(tag == 3)
     90         {
     91             getline(cin,str);
     92             printf("%d: %s
    ",tag,str.c_str());
     93             vv =  Keys[str];
     94         }
     95         else if(tag == 4)
     96         {
     97             getline(cin,str);
     98             printf("%d: %s
    ",tag,str.c_str());
     99             vv =  publisher[str];
    100         }
    101         else if(tag == 5)
    102         {
    103             int index;
    104             scanf("%d",&index);
    105             printf("%d: %04d
    ",tag,index);
    106             vv =  Year[index];
    107         }
    108 
    109         if(vv.empty())
    110         {
    111             printf("Not Found
    ");
    112         }
    113         for(int k = 0 ;k < vv.size();++k)
    114         {
    115             printf("%07d
    ",vv[k]);
    116         }
    117     }
    118     return 0;
    119 }


  • 相关阅读:
    粗看ES6之函数
    粗看ES6之变量
    https微信分享看不到图片的坑
    关于WebStorm,PhpStorm新版本输入中文问题
    ios下表单disabled样式重置
    关于IE的一些hack
    来自语文老师的教诲
    DP专题
    对近期参加的所有比赛的简略整理和好的idea的收集
    网络流学习
  • 原文地址:https://www.cnblogs.com/xiaoyesoso/p/5235294.html
Copyright © 2011-2022 走看看