PAT甲级1022 Digital Library
题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805480801550336
题意:
每一本书有一个id, 书名,作者,至多五个关键字,一个出版社名,出版社年份。
现在根据给定的书名或作者或关键字或出版社名或年份,按照id字典序大小输出符合条件的书。
思路:
对每一个属性都用map维护。
一个坑点是,前面说书的年份一定在1000-3000之间,但是查询的时候的年份不一定满足,而且这里输出的时候也要满足4位。测试点1就是和年份有关的。
#include<cstdio>
#include<cstdlib>
#include<map>
#include<set>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue> #define inf 0x7fffffff
using namespace std;
typedef long long LL;
typedef pair<string, string> pr; int n, m;
const int maxn = 1e4 + ; struct node{
string id;
string title;
string author;
string keyword[];
string publisher;
int year;
int keynum = ;
}book[maxn]; map<string, int>titlemp;
map<string, int>authormp;
map<string, int>keymp;
map<string, int>publishermp;
map<int, string>idmp;
int titletot, authortot, keytot, publishertot, idtot; vector<int> title[maxn], author[maxn], keyword[], publisher[], year[]; bool cmp(int a, int b)
{
int ida = stoi(idmp[a]), idb = stoi(idmp[b]);
return ida < idb;
} int main()
{
scanf("%d", &n);
for(int i = ; i < n; i++){
getchar();getline(cin, book[i].id);
idmp[i] = book[i].id; getline(cin, book[i].title);
if(titlemp.find(book[i].title) == titlemp.end()){
titlemp[book[i].title] = titletot++;
}
title[titlemp[book[i].title]].push_back(i);
getline(cin, book[i].author);
if(authormp.find(book[i].author) == authormp.end()){
authormp[book[i].author] = authortot++;
}
author[authormp[book[i].author]].push_back(i);
char ch;
while(){
cin>>book[i].keyword[book[i].keynum];
//cout<<book[i].keyword[book[i].keynum]<<endl;
if(keymp.find(book[i].keyword[book[i].keynum]) == keymp.end()){
keymp[book[i].keyword[book[i].keynum]] = keytot++;
}
keyword[keymp[book[i].keyword[book[i].keynum++]]].push_back(i);
ch = getchar();
if(ch == '\n')break;
}
getline(cin, book[i].publisher);
if(publishermp.find(book[i].publisher) == publishermp.end()){
publishermp[book[i].publisher] = publishertot++;
}
publisher[publishermp[book[i].publisher]].push_back(i);
cin>>book[i].year;
year[book[i].year - ].push_back(i);
} scanf("%d", &m);
while(m--){
int type;
scanf("%d: ", &type);
string s;
int id, y;
//getchar();
switch(type){
case :
getline(cin, s);
printf("1: ");cout<<s<<endl;
if(titlemp.find(s) == titlemp.end()){
printf("Not Found\n");
}
else{
id = titlemp[s];
sort(title[id].begin(), title[id].end(), cmp);
for(int i = ; i < title[id].size(); i++){
cout<<idmp[title[id][i]]<<endl;
}
}
break;
case :
getline(cin, s);
printf("2: ");cout<<s<<endl;
if(authormp.find(s) == authormp.end()){
printf("Not Found\n");
}
else{
id = authormp[s];
sort(author[id].begin(), author[id].end(), cmp);
for(int i = ; i < author[id].size(); i++){
cout<<idmp[author[id][i]]<<endl;
}
}
break;
case :
getline(cin, s);
printf("3: ");cout<<s<<endl;
if(keymp.find(s) == keymp.end()){
printf("Not Found\n");
}
//cout<<id<<endl;
else{
id = keymp[s];
sort(keyword[id].begin(), keyword[id].end(), cmp);
for(int i = ; i < keyword[id].size(); i++){
cout<<idmp[keyword[id][i]]<<endl;
}
}
break;
case :
getline(cin, s);
printf("4: ");cout<<s<<endl;
if(publishermp.find(s) == publishermp.end()){
printf("Not Found\n");
}
else{
id = publishermp[s];
sort(publisher[id].begin(), publisher[id].end(), cmp);
for(int i = ; i < publisher[id].size(); i++){
cout<<idmp[publisher[id][i]]<<endl;
}
}
break;
case :
cin>>s;
printf("5: ");cout<<s<<endl;
y = stoi(s);
if( y< || y > || year[y - ].size() == ){
printf("Not Found\n");
}
else{
sort(year[y - ].begin(), year[y - ].end(), cmp);
for(int i = ; i < year[y - ].size(); i++){
cout<<idmp[year[y - ][i]]<<endl;
}
}
break;
}
}
return ;
}
PAT甲级1022 Digital Library的更多相关文章
- pat 甲级 1022. Digital Library (30)
1022. Digital Library (30) 时间限制 1000 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A Di ...
- 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甲级——A1022 Digital Library
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 ...
- 1022 Digital Library——PAT甲级真题
1022 Digital Library A Digital Library contains millions of books, stored according to their titles, ...
- PAT 1022 Digital Library[map使用]
1022 Digital Library (30)(30 分) A Digital Library contains millions of books, stored according to th ...
- 1022 Digital Library (30 分)
1022 Digital Library (30 分) A Digital Library contains millions of books, stored according to thei ...
随机推荐
- ArcGis汇总篇
ArcGis-javascript-API下载 bigemap.太乐地图 可下载地图文件 用arcgis for js 可以河流流域水质图 ArcGis导出shp文件(dbf.prj.sbn.sbx. ...
- 安装tftp
#!/bin/bash # tftp install # 20180711 # 仅测试过操作系统 ubuntu 16.04 download_url='http://img.fe.okjiaoyu.c ...
- 子级用了float浮动之后,如何撑开父元素,让父元素div自动适应高度
方法一:对父级设置固定高度 假如以上案例,我们知道内部div高度100px,那对父级设置css height为100px看看效果. 此方法缺点,父级是固定高度,而不随内容高度自适应高度,没高度.此方法 ...
- 使用 JS 嵌入的方式来加载 Flash 插件,在各浏览器中播放视频
嵌入插件 使用 object 和 embed 标签 这种方法用到的是 Object 和 Embed 标签,可以看到 object 的很多参数和 embed 里面的很多属性是重复的.浏览器兼容性,有的浏 ...
- Jenkins--发送邮件配置
使用Jenkins可以进行构建,并可以发送邮件.今天我们来讲一下邮件的配置. 首先:下载安装插件: 进入[Jenkins-系统管理-插件管理-可选插件],搜索“Email Extension”进行安装 ...
- 查不到opencv版本的问题
检查opencv版本:pkg-config --modversion opencv 前两天卸载了opencv3.0,想重装2.4版本.安装是没有问题,但现在查不到opencv版本,程序也编译不通过. ...
- 【Java编程思想笔记】反射
文章参考:学习网站 how2java.cn 参考博客:(敬业的小码哥)https://blog.csdn.net/sinat_38259539/article/details/71799078 (青色 ...
- Django ORM中,如何使用Count来关联对象的子集数量
示例models 解决方法 有时候,我们想要获取一个对象关联关系的数量,但是我们不要所有的关联对象,我们只想要符合规则的那些关联对象的数量. 示例models # models.py from dja ...
- MinGW GCC 8.1.0 2018年5月2日 出炉啦
MSYS_MinGW-w64_GCC_810_x86-x64.7z for x86 x64 59.0 MB发布日期: 2018-05-04 下载地址:https://sourceforge.net/p ...
- Vue相关目录
cli入门-项目搭建 组件 Router路由 生命周期 数据监听 cli搭建web服务介绍 vuex和axios介绍