题意

  输入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. 关于简单的三层的简化(bll,dal,model)的封装这里全部都在一个文件主要在于明白意思

    using System;using System.Collections.Generic;using System.Linq;using System.Text; namespace 封装泛型CRU ...

  2. DataStage 二、InfoSphere Information Server进程的启动和停止

    DataStage序列文章 DataStage 一.安装 1 关于进程需要了解的基础知识 名称 说明 ASB代理进程 通信代理程序,它的作用是协助层与层之间的通信,默认端口是31531,它以后台进程的 ...

  3. Excel应用程序如何创建数据透视表

    原文作者:andreww 原文链接: http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmat ...

  4. Appium自动化测试-iOS

    Appium的哲学 我们相信,对原生应用的自动化测试,应当不必要包含其他的SDK组件或者特别编译您的App,并且应当可以选择任何您喜欢的测试方法,框架和工具.基于这些出发点我们开发了Appium.现在 ...

  5. eclipse中maven install提示编码GBK的不可映射字符

    今天在eclipse中使用Maven编译项目源代码时,结果如下了如下的错误 在Java源码中没有提示任何报错,即便是改掉项目编码也是不行,如下图所示:

  6. 51nod1057—N的阶乘—(大数阶乘)

    1057 N的阶乘  基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题  收藏  关注 输入N求N的阶乘的准确值.   Input 输入N(1 <= N <=  ...

  7. 初步理解IOC和DI和AOP模式

    初步理解IOC和DI和AOP模式 控制反转(IOC) 控制反转(IOC,Inversion of Control)是一种转主动为被动关系的一种编程模式,有点类似于工厂模式,举个栗子, 下面这个这不是I ...

  8. .Net C# 阿拉伯数字转为中文金额数字

    一个练习,将阿拉伯数字转为中文金额数字,针对包含整数的金额有问题 代码: public string ReturnStr(string inputNum) { ", }; string[] ...

  9. TestNG学习笔记目录

    学习TestNG主要用于GUI自动化测试使用,学习目录随进度不断更新.文档内容主要是翻译官方doc,同时加入自己的理解和案例.如有理解偏差欢迎指正 一.TestNG Eclipse plug-in 安 ...

  10. 【ocp-12c】最新Oracle OCP-071考试题库(47题)

    47.(10-6)choose two You need to calculate the number of days from 1st January 2007 till date. Dates ...