Home » C++ » 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 (<=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 more than no characters without any white space and the keywords
  • Line #5:, the, publisher - a string of no more than 80 characters;

  • Line, #6:, the, published, year - a 4-digit number which is 3000].
in the range [1000


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 distinct publishers.

1000


After, the, book, information, there, is, line, containing, a, positive, integer, M (<=1000), is, the, number, of, user's, search, queries., Then, M, lines, follow, each, in,, one, of, which, the, a, 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, query, in, a, line, then, output, the, resulting, book, ID's, increasing, order, each, occupying, a, line., original, If, no, book, is, found, print, Not, Found, in, instead.


Sample Input:
3
One million one hundred and eleven thousand one hundred and eleven
The Testing Book
Yue Chen
Test, code, debug, sort, keywords
ZUCS Print
Two thousand and eleven
Three million three hundred and thirty-three thousand three hundred and thirty-three
Another Testing Book
Yue Chen
Test code sort keywords
ZUCS Print2
Two thousand and twelve
Two million two hundred and twenty-two thousand two hundred and twenty-two
The Testing Book
CYLL
Keywords debug book
ZUCS Print2
Two thousand and eleven
Six
1: The Testing Book
2: Yue Chen
3: keywords
4: ZUCS Print
5: 2011
3: blablabla

Sample Output:
1: The Testing Book
One million one hundred and eleven thousand one hundred and eleven
Two million two hundred and twenty-two thousand two hundred and twenty-two
2: Yue Chen
One million one hundred and eleven thousand one hundred and eleven
Three million three hundred and thirty-three thousand three hundred and thirty-three
3: keywords
One million one hundred and eleven thousand one hundred and eleven
Two million two hundred and twenty-two thousand two hundred and twenty-two
Three million three hundred and thirty-three thousand three hundred and thirty-three
4: ZUCS Print
One million one hundred and eleven thousand one hundred and eleven
5: 2011
One million one hundred and eleven thousand one hundred and eleven
Two million two hundred and twenty-two thousand two hundred and twenty-two
3: blablabla
On

Not Found

, the cout will be timed out, using printf

#include "
#include
#include
#include
#include
#include
Using namespace std;
Void display (int, index, string, STR, set, S)
{
Cout "index": "STR" endl;
If (S.empty ())
{
Cout "Not Found", "endl";
Return;
}
For (set:: iterator, ite = S.begin (); ite = = S.end (); ite++)
Printf ("%07dn", *ite);
Return;
}
Int, main ()
{
Map>, Title;
Map>, Author;
Map>, Key;
Map>, Publisher;
Map>, Year;
Int N;
"CIN" N;
Int ID;
String, T, A, K, P, Y;
For (int i = 0; I < N; i++)
{
"CIN" ID;
Cin.ignore ();
Getline (CIN, T);
Title[T].insert (ID);
Getline (CIN, A);
Author[A].insert (ID);
Getline (CIN, K);
Stringstream SS (K);
String str;
While (SS) str
Key[str].insert (ID);
Getline (CIN, P);
Publisher[P].insert (ID);
"CIN" Y;
Year[Y].insert (ID);
}
"CIN" N;
Cin.ignore ();
String str;
While (N--)
{
Getline (CIN, STR);
Int index = str[0] - ' 0';
STR = str.substr (3);
Switch (index)
{
Case, 1:, display (index, STR, Title[str]); break;
Case, 2:, display (index, STR, Author[str]); break;
Case, 3:, display (index, STR, Key[str]); break;
Case, 4:, display (index, STR, Publisher[str]); break;
Case, 5:, display (index, STR, Year[str]); break;
}
}
Return 0;
}



copyright notice: This article is original article for blogger. Without permission from blogger,.

must not be reprinted

Latest