pat1022. Digital Library (30)

Source: Internet
Author: User

1022. Digital Library (30) time limit MS Memory limit 65536 KB code length limit 16000 B procedure StandardAuthor Chen, Yue

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

Submit Code

Idea: This problem seems to be very troublesome, but need careful analysis after the idea will be more clear. Learn to take advantage of the characteristics of map and set, and the combination of both, such as map<string,set<int> > be sure to remember that there is a space here, where you need an iterator to access the set and access only through an iterator, insert is required when inserting.

1#include <Set>2#include <map>3#include <cstdio>4#include <algorithm>5#include <iostream>6#include <cstring>7#include <queue>8#include <vector>9#include <cmath>Ten using namespacestd; One /* A 0:id - 1:a Book title - 2:name of an author the 3:a key word - 4:name of a publisher - 5:a 4-digit number representing the year - */ +map<string,Set<int> > book[6]; - intMain () { +     //freopen ("D:\\input.txt", "R", stdin); A     intn,m; atscanf"%d",&n); -     intI,j,id; -     stringstr; -      for(i=0; i<n;i++){ -scanf"%d",&ID); -GetChar ();//use Cin.getline () Special note: Cin.getline () is read into the newline character in          for(j=1; j<=2; j + +){ - getline (CIN,STR); to Book[j][str].insert (ID); +             //cout<<j<< "" <<str<<endl; -             //cout<<book[j][str].size () <<endl; the         } *          $          while(cin>>str) {Panax Notoginsengbook[3][str].insert (ID); -             //cout<<3<< "" <<str<<endl; the             //cout<<book[3][str].size () <<endl; +             if(GetChar () = ='\ n'){ A                  Break; the             } +         } -          $          $          for(j=4; j<=5; j + +){ - getline (CIN,STR); - Book[j][str].insert (ID); the             //cout<<j<< "" <<str<<endl; -             //cout<<book[j][str].size () <<endl;Wuyi         } the     } -      Wuscanf"%d",&m); -      for(i=0; i<m;i++){ Aboutscanf"%d:",&ID); $printf"%d:", id); - getline (CIN,STR); -cout<<str<<Endl; -         if(!Book[id].count (str)) { Aprintf"Not found\n"); +             Continue; the         } -         Set<int>:: iterator it; $          for(It=book[id][str].begin (); It!=book[id][str].end (); it++){ theprintf"%07d\n", *it);//cout<<*it<<endl; the         } the     } the     return 0; -}

pat1022. 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.