A1022. Digital Library (30)

Source: Internet
Author: User

A Digital Library contains millions of books, stored according to their titles, authors, key words of their abstracts, pub Lishers, and published years. The assigned a unique 7-digit number as its ID. Given any query from a reader, you is supposed to output the resulting books, sorted in increasing order of their ID ' s.

Input Specification:

Each input file contains the one test case. For each case, the first line contains a positive integer N (<=10000) which are 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 characters;
    • Line #3: The author-a string of no more than characters;
    • Line #4: The key words-all word is a string of no more than characters without all white space, and the keywords AR e separated by exactly one space;
    • Line #5: The publisher-a string of no more than characters;
    • Line #6: The published year-a 4-digit number which are in the range [1000, 3000].

It is assumed this belongs to one author only, and contains no more than 5 key words; There is no more than-distinct key words in total; And there is no more than distinct publishers.

After the book information, there are a line containing a positive integer M (<=1000) which is the number of the user's sear CH 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 with a line and then output the resulting book ID's in increasing order with each OC Cupying a line. If No book is found, the print "not found" instead.

Sample Input:

31111111The testing Bookyue chentest Code Debug Sort keywordszucs print20113333333another testing Bookyue chentest code so RT Keywordszucs print220122222222the Testing bookcyllkeywords Debug Bookzucs print2201161:the Testing Book2:yue chen3:k Eywords4:zucs Print5:20113:blablabla

Sample Output:

1:the testing Book111111122222222:yue Chen111111133333333:keywords1111111222222233333334:ZUCS Print11111115: 2011111111122222223:blablablanot 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>Ten#include <string> One#include <map> A using namespacestd; -map<string,Set<int> >mptitle,mpauthor,mpkey,mppub,mpyear; - //a keyword can correspond to multiple IDs, so use set<int> the voidQuery (map<string,Set<int> &GT;&AMP;MP,string&str) - { -     if(Mp.find (str) ==mp.end ()) printf ("Not found\n"); -     Else{ +      for(Set<int>::iterator It=mp[str].begin (); It!=mp[str].end (); it++)//full output for the Found keyword -     { +         //Note that the SET<INT> is used here, not map<string,set<int>. Aprintf"%07d\n",*it);  at          -     } -     } - } -  -   in intMain () { -     intN,id; to     stringtitle,author,key,pub,year; +scanf"%d",&n); -      for(intI=0; i<n;i++) the     { *scanf"%d",&ID); $         CharC=getchar ();//Get line breakPanax Notoginseng getline (cin,title); - Mptitle[title].insert (ID); the getline (cin,author); + Mpauthor[author].insert (ID); A          while(cin>>key) the         { + Mpkey[key].insert (ID); -C=GetChar (); $             if(c=='\ n') Break; $         }  - getline (cin,pub); - Mppub[pub].insert (ID); the getline (cin,year); - Mpyear[year].insert (ID);Wuyi     }  the     stringtemp; -     intM,type; Wuscanf"%d",&m); -      for(intI=0; i<m;i++) About     { $scanf"%d:", &type);//The format is important here. The colon cannot be less - getline (cin,temp); -cout<<type<<": "<<temp<<Endl; -         if(type==1) query (mptitle,temp); A         Else if(type==2) query (mpauthor,temp); +         Else if(type==3) query (mpkey,temp); the         Else if(type==4) query (mppub,temp); -         Elsequery (mpyear,temp); $     } the     return 0; the}

A1022. Digital Library (30)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.