【算法笔记】A1022 Digital Library
题意
输入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的更多相关文章
- A1022. Digital Library
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] A1022 Digital Library
[题目大意] 给出几本书的信息,包括编号,名字,出版社,作者,出版年份,关键字:然后给出几个请求,分别按照1->名字,2->出版社等对应信息查询符合要求的书的编号. [思路] 模拟. [坑 ...
- 1022. Digital Library (30)
A Digital Library contains millions of books, stored according to their titles, authors, key words o ...
- 学习Java 以及对几大基本排序算法(对算法笔记书的研究)的一些学习总结(Java对算法的实现持续更新中)
Java排序一,冒泡排序! 刚刚开始学习Java,但是比较有兴趣研究算法.最近看了一本算法笔记,刚开始只是打算随便看看,但是发现这本书非常不错,尤其是对排序算法,以及哈希函数的一些解释,让我非常的感兴 ...
- 1022. Digital Library (30) -map -字符串处理
题目如下: A Digital Library contains millions of books, stored according to their titles, authors, key w ...
- PAT1022.:Digital Library
1022. Digital Library (30) 时间限制 1000 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A Di ...
- PAT 甲级 1022 Digital Library
https://pintia.cn/problem-sets/994805342720868352/problems/994805480801550336 A Digital Library cont ...
- PAT 1022 Digital Library[map使用]
1022 Digital Library (30)(30 分) A Digital Library contains millions of books, stored according to th ...
随机推荐
- 转载:字符串hash总结(hash是一门优雅的暴力!)
转载自:远航休息栈 字符串Hash总结 Hash是什么意思呢?某度翻译告诉我们: hash 英[hæʃ] 美[hæʃ]n. 剁碎的食物; #号; 蔬菜肉丁;vt. 把…弄乱; 切碎; 反复推敲; 搞糟 ...
- ecshop适配php
https://www.cnblogs.com/xiwang6428/p/5460155.html
- [SoapUI] Mock Service
https://www.soapui.org/getting-started/mock-services.html
- WAMP不能启动, 一直处于红色图标或者橙色图标的解决办法
WAMP不能启动, 一直处于红色图标(正常启动为绿色吧) 考虑是端口的问题,我找到wamp文件夹中的wamp\bin\apache\apache2.2.22\conf路径下的httpd.conf文件, ...
- 如何把App放在服务器上供用户下载
如何把App放在服务器上供用户下载 有时候做了个简单的App想把App给朋友帮忙测试一下,却发现上传到各种平台很麻烦,肿么办?难道一个个拷贝,那也太low啦,不是咱程序员该干的事儿,好的话不多说,开搞 ...
- SpringBoot2.0WebFlux响应式编程知识总结
- 我的border能自定义四角之border-radius : 左上角,右上角,左下角,右下角。
1 边框:border: 1px solid #0081df; 2 想要单独加上四个圆角: border-bottom-left-radius: 5px; border-top-left-radius ...
- Linux 基础教程 38-文件下载
什么是wget wget用原始帮助里面的英文来讲就是:The non-interactive network downloader,非交互式网络下载器.它支持HTTP.HTTPS.FTP等协议 ...
- Codeforces761B Dasha and friends 2017-02-05 23:34 162人阅读 评论(0) 收藏
B. Dasha and friends time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- JAVA常见面试题及解答
JAVA相关基础知识1.面向对象的特征有哪些方面 1.抽象:抽象就是忽略一个主题中与当前目标无关的那些方面,以便更充分地注意与当前目标有关的方面.抽象并不打算了解全部问题,而只是选择其中的一部分,暂时 ...