zoukankan      html  css  js  c++  java
  • 1022 Digital Library (30 分)

    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 (≤) 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 (≤) 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

    又是一道模拟题, 这题30分不值,这题模拟也太简单了。
    最后要排个序再输出。
     1 #include <bits/stdc++.h>
     2 #define N 10005
     3 using namespace std;
     4 int n,m;
     5 struct Node{
     6     string l1,l2,l3,l4,l5,l6;
     7 }node[N];
     8 map<string,vector<string> > mp[6];
     9 
    10 void addstr(string s1, string s2){
    11     s1 += ' ';
    12     string sk;
    13     for(int i = 0 ; i < s1.length(); i++){
    14         if(s1[i] == ' '){
    15             mp[3][sk].push_back(s2);
    16             sk = "";        
    17         }else{
    18             sk += s1[i];
    19         }
    20     }
    21 }
    22 
    23 void solve(int x, string ss){
    24     if(mp[x][ss].size() > 0){
    25         sort(mp[x][ss].begin(), mp[x][ss].end());
    26         for(int i = 0; i < mp[x][ss].size(); i++ )
    27             cout << mp[x][ss][i] << endl;
    28     }else{
    29         cout <<"Not Found"<<endl;
    30     }
    31 }
    32 int main(){
    33     cin >> n;
    34     getchar();
    35     for(int i = 0; i < n; ++i){
    36         getline(cin,node[i].l1);
    37         getline(cin,node[i].l2);
    38         getline(cin,node[i].l3);
    39         getline(cin,node[i].l4);
    40         getline(cin,node[i].l5);
    41         getline(cin,node[i].l6);
    42         mp[1][node[i].l2].push_back(node[i].l1);
    43         mp[2][node[i].l3].push_back(node[i].l1);
    44         addstr(node[i].l4, node[i].l1);
    45         mp[4][node[i].l5].push_back(node[i].l1);
    46         mp[5][node[i].l6].push_back(node[i].l1);
    47     }
    48     cin >> m;
    49     getchar();
    50     string st, ss;
    51     while(m--){
    52         getline(cin,st);
    53         cout << st << endl;
    54         ss = st.substr(3,st.length()-3);
    55         if(st[0] == '1'){
    56             solve(1, ss);
    57         }else if(st[0] == '2'){
    58             solve(2, ss);
    59         }else if(st[0] == '3'){
    60             solve(3, ss);
    61         }else if(st[0] == '4'){
    62             solve(4, ss);
    63         }else{
    64             solve(5, ss);
    65         }
    66     }
    67     return 0;
    68 }
  • 相关阅读:
    js控制表格隔行变色
    浅谈css的伪元素::after和::before
    CSS 背景色变化 结构化伪类的练习
    css清除浮动的几种方式,哪种最合适?
    怎么去检测浏览器支不支持html5和css3?
    display:flex 布局详解(2)
    css3弹性盒子display:flex
    Referer和空Referer
    不要懒惰,坚持每周总结一篇博客
    比较2个文件的不同处
  • 原文地址:https://www.cnblogs.com/zllwxm123/p/11048854.html
Copyright © 2011-2022 走看看