pat 甲级 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 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:
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
题意:根据给定的信息,查找该信息出自哪本书
思路:这题主要是一个输入问题,信息查找只要字符串进行比较即可。
AC代码:
#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<set>
#include<queue>
#include<map>
using namespace std;
#define INF 0x3f3f3f
#define N_MAX 10000+5
typedef long long ll;
struct book{
string id, title,auther,publisher,publish_year;
vector<string>key;
bool operator < (const book&b) {
return id < b.id;
}
};
int n;
vector<book>vec;
int main() {
while (scanf("%d",&n)!=EOF) {
getchar();
for (int i = ; i < n;i++) {
book b;
getline(cin, b.id);
getline(cin, b.title);
getline(cin, b.auther);
do {
string tmp; cin >> tmp;
b.key.push_back(tmp);
} while (getchar()!='\n');
getline(cin, b.publisher);
getline(cin, b.publish_year);
vec.push_back(b);
}
sort(vec.begin(),vec.end());
int m; cin >> m;
while(m--) {
vector<book>res;
int cs; string s;
scanf("%d: ", &cs);
getline(cin,s); for (int i = ; i < vec.size();i++) {
if (s == vec[i].auther||s == vec[i].id||s==vec[i].publisher||s==vec[i].publish_year||s==vec[i].title) { res.push_back(vec[i]);continue; }
else {
for (int j = ; j < vec[i].key.size(); j++) {
if (s == vec[i].key[j]) {
res.push_back(vec[i]); break;
}
}
}
}
printf("%d: %s\n", cs, s.c_str());
if (res.size()) {
for (int i = ; i < res.size(); i++) {
cout << res[i].id << endl;
}
}
else puts("Not Found");
}
}
return ;
}
pat 甲级 1022. Digital Library (30)的更多相关文章
- PAT 甲级 1022 Digital Library (30 分)(字符串读入getline,istringstream,测试点2时间坑点)
		
1022 Digital Library (30 分) A Digital Library contains millions of books, stored according to thei ...
 - PAT 甲级 1022 Digital Library
		
https://pintia.cn/problem-sets/994805342720868352/problems/994805480801550336 A Digital Library cont ...
 - PAT Advanced 1022 Digital Library (30 分)
		
A Digital Library contains millions of books, stored according to their titles, authors, key words o ...
 - PAT A 1022. Digital Library (30)【结构体排序检索】
		
https://www.patest.cn/contests/pat-a-practise/1022 直接模拟, 输入,按id排序,检索 #include <iostream> #incl ...
 - PAT甲级1022 Digital Library
		
题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805480801550336 题意: 每一本书有一个id, 书名,作 ...
 - 1022 Digital Library (30 分)
		
1022 Digital Library (30 分) A Digital Library contains millions of books, stored according to thei ...
 - 1022. Digital Library (30)
		
A Digital Library contains millions of books, stored according to their titles, authors, key words o ...
 - 1022. Digital Library (30) -map -字符串处理
		
题目如下: A Digital Library contains millions of books, stored according to their titles, authors, key w ...
 - 1022 Digital Library (30)(30 point(s))
		
problem A Digital Library contains millions of books, stored according to their titles, authors, key ...
 
随机推荐
- v4l2解析
			
v4l2的学习建议和流程解析: http://www.cnblogs.com/silence-hust/p/4464291.html 补充: 枚举设备所支持的image format: VIDIOC_ ...
 - Django之视图和URL配置
			
1.在创建项目时,Django会自动创建URL配置,在urls.py文件中 文件的默认内容如下所示: """mysite URL Configuration The ur ...
 - Codeforces Round #461 (Div. 2) C. Cave Painting
			
C. Cave Painting time limit per test 1 second memory limit per test 256 megabytes Problem Descriptio ...
 - 实验一 查看CPU和内存,用机器指令和汇编指令编程
			
(1):使用debug,将下面的程序段写入内存,逐条执行,观察每条指令执行后,CPU中相关寄存器中内存的变化. 机器码 汇编指令 b8 20 4e mov ax,4E20H 05 ...
 - Android四大组件之服务
			
创建一个服务,并与活动绑定 作为安卓四大组件之一的服务,毫无例外也要在manifast中进行注册 新建服务类继承于Service,并覆盖onBind( )方法,用于与活动绑定 public class ...
 - sql中比较大小
			
if object_id('tempdb..#dataOldNew1') is not null drop table #dataOldNew1 select distinct store_cd ,i ...
 - SSRS 制作报表时报错: 超时时间已到。在操作完成之前超时时间已过或服务器未响应。
			
转载注明出处,原文地址:http://www.cnblogs.com/zzry/p/5718739.html 在用ssrs 制作报表时报如下错误 错误信息截图: 看到如上错误第一个想到的解决方法就是 ...
 - laravel5.2总结--序列化
			
序列化 构建Json格式的API接口时,经常需要转换 '模型' 和 '关联关系' 为数组或者JSON. 1>转换模型为数组: $user = App\User::with('roles')- ...
 - Gradle task
			
本文来自网易云社区 作者:孙有军 1:gradle脚本是使用groovy语言写的(DSL),groovy中有一个重要的概念闭包(Closure),Closure是一段单独的代码块,它可以接收参数,返回 ...
 - MFC DLL  可以封装MFC的窗体 供别的MFC程序使用
			
MFC DLL 可以封装MFC的窗体 供别的MFC程序使用 在庞大程序分工里面 非常可取. 可以细分每个窗体就是单独的 模块. [后续不断完善]