PAT
来源:互联网 发布:淘宝避开同款教程 编辑:程序博客网 时间:2024/06/06 16:27
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:31111111The Testing BookYue Chentest code debug sort keywordsZUCS Print20113333333Another Testing BookYue Chentest code sort keywordsZUCS Print220122222222The Testing BookCYLLkeywords debug bookZUCS Print2201161: The Testing Book2: Yue Chen3: keywords4: ZUCS Print5: 20113: blablablaSample Output:
1: The Testing Book111111122222222: Yue Chen111111133333333: keywords1111111222222233333334: ZUCS Print11111115: 2011111111122222223: blablablaNot Found
给定条件:
1.N本书的属性(编号,名字,作者,关键字,出版社,出版时间)
要求:
1.给定一个属性,输出具有该属性的书的编号
求解:
1.在输出处理的时候,每一个属性对应一个set容器,容器中是具有该属性的书籍编号
2.遍历set容器输出结果
#include <iostream>#include <cstdio>#include <map>#include <set>using namespace std;map<string, set<int> > title, author, kw, pub, year;int n, m, id;string ttitle, tauthor, tkw, tpub, tyear, str;void query(map<string, set<int> > &book, string &str) {if(book.find(str) != book.end()) {for(set<int>::iterator it = book[str].begin(); it != book[str].end(); it++) {printf("%07d\n", *it);}} else {printf("Not Found\n");}}int main(){freopen("input.txt", "r", stdin);scanf("%d", &n);for(int i = 0; i < n; i++) {scanf("%d", &id);getchar();getline(cin,ttitle);title[ttitle].insert(id);getline(cin, tauthor);author[tauthor].insert(id);while(cin>>tkw) {kw[tkw].insert(id);char c = getchar();if(c == '\n') {break;}}getline(cin, tpub);pub[tpub].insert(id);getline(cin, tyear);year[tyear].insert(id);}scanf("%d",&m);for(int i = 0; i < m; i++) {scanf("%d: ",&n);getline(cin, str);cout<<n<<": "<<str<<endl;if(n == 1) {query(title, str);} else if(n == 2) {query(author, str);} else if(n == 3) {query(kw, str);} else if(n == 4) {query(pub, str);} else if(n == 5) {query(year, str);}}return 0;}
- pat
- 【PAT】
- PAT
- PAT
- PAT
- PAT
- PAT
- PAT
- PAT
- PAT
- PAT
- pat
- PAT
- PAT
- PAT
- PAT
- PAT
- PAT
- 11月15日云栖精选夜读:分布式服务框架Dubbo疯狂更新!阿里开源要搞大事情?
- hive字符串基础操作函数
- 数据结构与算法分析(Java语言描述)(21)—— 并查集基础
- app model下 build.gradle 修改一下就卡的不行解决办法
- 输出符合条件的指定行
- PAT
- 共轭方向法和共轭梯度法
- api文档的安装
- 天梯地图(30 分)
- Redis实现原理:数据同步机制分析
- dialog.show()异常
- 喝汽水,1瓶汽水1元,2个空瓶可以换一瓶汽水,给20元,可以多少汽水。
- libxxx.so- text relocations问题的终极解决方案
- 吉信通短信接口(HTTP协议) java