题意

  输入n本书的信息:id,书名,作者,关键字,出版社,出版年份。搜索图书,输出id。

思路

  定义5个map<string, set<int> >,分别存放Title, Author, Word, Publishier, Year与id的映射关系,然后只需要考虑怎么输入就可以了。注意因为字符串和map的参数传递很慢,所以如果把查询写成函数,必须对参数进行引用,否则会导致运行超时。

code:

 #include<bits/stdc++.h>
using namespace std;
map<string, set<int> > Title, Author, Word, Publishier, Year;
void query(map<string, set<int> > &mp, string &str){
if(mp.find(str) == mp.end()) cout<<"Not Found"<<endl;
else{
for(set<int>::iterator it = mp[str].begin(); it!=mp[str].end(); it++){
printf("%07d\n", *it);
}
}
}
int main(){
int n, m, id, type;
string tit, aut, word, pub, year, search;
cin>>n;
for(int i = ; i < n; i++){
cin>>id;
getchar();
getline(cin, tit);
Title[tit].insert(id);
getline(cin, aut);
Author[aut].insert(id);
while(cin>>word){
Word[word].insert(id);
char c = getchar();
if(c == '\n') break;
}
getline(cin, pub);
Publishier[pub].insert(id);
getline(cin, year);
Year[year].insert(id);
}
cin>>m;
for(int i = ; i < m; i++){
scanf("%d: ", &type);
getline(cin, search);
cout<<type<<": "<<search<<endl;
if(type == ) query(Title, search);
else if(type == ) query(Author, search);
else if(type == ) query(Word, search);
else if(type == ) query(Publishier, search);
else if(type == ) query(Year, search);
}
return ;
}

【算法笔记】A1022 Digital Library的更多相关文章

  1. A1022. Digital Library

    A Digital Library contains millions of books, stored according to their titles, authors, key words o ...

  2. PAT甲级——A1022 Digital Library

    A Digital Library contains millions of books, stored according to their titles, authors, key words o ...

  3. [PAT] A1022 Digital Library

    [题目大意] 给出几本书的信息,包括编号,名字,出版社,作者,出版年份,关键字:然后给出几个请求,分别按照1->名字,2->出版社等对应信息查询符合要求的书的编号. [思路] 模拟. [坑 ...

  4. 1022. Digital Library (30)

    A Digital Library contains millions of books, stored according to their titles, authors, key words o ...

  5. 学习Java 以及对几大基本排序算法(对算法笔记书的研究)的一些学习总结(Java对算法的实现持续更新中)

    Java排序一,冒泡排序! 刚刚开始学习Java,但是比较有兴趣研究算法.最近看了一本算法笔记,刚开始只是打算随便看看,但是发现这本书非常不错,尤其是对排序算法,以及哈希函数的一些解释,让我非常的感兴 ...

  6. 1022. Digital Library (30) -map -字符串处理

    题目如下: A Digital Library contains millions of books, stored according to their titles, authors, key w ...

  7. PAT1022.:Digital Library

    1022. Digital Library (30) 时间限制 1000 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A Di ...

  8. PAT 甲级 1022 Digital Library

    https://pintia.cn/problem-sets/994805342720868352/problems/994805480801550336 A Digital Library cont ...

  9. PAT 1022 Digital Library[map使用]

    1022 Digital Library (30)(30 分) A Digital Library contains millions of books, stored according to th ...

随机推荐

  1. WordPress 3.7.1-web截屏插件整合教程-Xproer.ScreenCapture

    插件下载(PHP):wordpress 3.7.1, 说明:由于许多插件可能使用相同钩子,导致冲突,所以提供手支方式整合. 1.上传插件目录. 说明:WordPress 3.7.1 使用的是TinyM ...

  2. tera term通过ttl脚本 自动连接服务器

    在现在的这个公司一直使用tera term来远程连接服务器,感觉很方便,特别是它的ttl脚本配置的自动连接.有时候我们可能无法直接连接到目标服务器,需要通过ssh经过多个中间服务器才能连接到目标服务器 ...

  3. CSS—— em的详解

    字体大小在浏览器的默认样式表中有规定.一般采用em为单位,也就是相对单位,1em=16像素. 同时,像P h1等等标签都采用浏览器默认的em单位,P为1em,h1为2em等等. 两条重要的规则: 1. ...

  4. 20155335俞昆《java程序设计》第6周总结

    20155335    <Java程序设计>第6周学习总结 ##  教材学习内容总结 首先,我们需要了解输入和输出的关系,我想,这不同于c语言中的输入和输出,我们首先明白,Java中以串流 ...

  5. 层层递进Struts1(五)之处理流程

    这篇博客我们深入Struts框架执行部分源码,从ActionServlet的process函数开始,看一下其内在的执行过程. 流程图 以下流程图展示的是ActionServlet和RequestPro ...

  6. FMX.Platform.TApplicationEvent

    FMX.Platform.TApplicationEvent http://docwiki.embarcadero.com/Libraries/Seattle/en/FMX.Platform.TApp ...

  7. IDEA 配置SSH2

    系统换成了mac os,因为喜欢它的界面体验,同时受不了win下面系统对硬盘的疯狂访问.发现在mac下面,IDEA真的不错,速度上快,并且它的智能提示真的很厉害.但是导入一个myeclipse的ssh ...

  8. Linux Guard Service - 进程分裂与脱离

    进程分裂更名 void set_ps_name(char *name) { prctl(PR_SET_NAME, name); } 修改进程长名称 备份进程环境变量空间 for (i = 1; i & ...

  9. js ajax请求传token

    js  ajax请求传token 方法一: headers: { Authorization: "BasicAuth " + token } 方法二: beforeSend: fu ...

  10. Oracle数据库exp和imp方式导数据

    这里导入导出路径都在D盘下,默认文件名为:example.dmpexp方式导出数据相关参数项如下: 关键字  说明  默认USERID                     用户名/口令FULL   ...