pat 1022 digital library
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <fstream>
#include <algorithm>
#include <iomanip>
using namespace std;
//利用map键的唯一性
//建立key为关键词,value为id的map map<string, vector<int>> name;
map<string, vector<int>> author;
map<string, vector<int>> keyWord;
map<string, vector<int>> press;
map<string, vector<int>> year;//对出版年同样做string对待 int main(void)
{
//ifstream fin("data.txt"); int num, bookID;
cin>>num;
string temp, nameTemp, authorTemp, keyWordLine,
keyWordTemp, pressTemp, yearTemp;
for(int i=; i<num; i++)
{
cin>>bookID;
getline(cin, temp);//这里多余的输入去掉回车符
getline(cin, nameTemp);
name[nameTemp].push_back(bookID);
//map下标操作:
//1.如果存在key,则返回对应的value
//2.如果key不存在,插入key getline(cin, authorTemp);
author[authorTemp].push_back(bookID); //输入一行字符串并且逐个分解单词
getline(cin, keyWordLine);
istringstream stream(keyWordLine);
while(stream >> keyWordTemp)
keyWord[keyWordTemp].push_back(bookID); getline(cin, pressTemp);
press[pressTemp].push_back(bookID); getline(cin, yearTemp);
year[yearTemp].push_back(bookID);
} int queryNum;
cin>>queryNum;
string query;
getline(cin, temp);//同样去掉整型后面的回车符 for(int i=; i<queryNum; i++)
{
getline(cin, query);
string queryText(query.begin()+, query.end());//拷贝关键词
map<string, vector<int>>::iterator it = name.find(queryText);
if(it != name.end())//关键词存在
{
cout<<query<<endl;
sort(it->second.begin(), it->second.end());//按id顺序
for(int j=; j<it->second.size(); j++)
cout<<setfill('')<<setw()<<it->second[j]<<endl;
continue;//按照题意,关键词是name keyword author等中的一种
//查询到则进行下一次查询
} it = author.find(queryText);
if(it != author.end())
{
cout<<query<<endl;
sort(it->second.begin(), it->second.end());
for(int j=; j<it->second.size(); j++)
cout<<setfill('')<<setw()<<it->second[j]<<endl;
continue;
} it = keyWord.find(queryText);
if(it != keyWord.end())
{
cout<<query<<endl;
sort(it->second.begin(), it->second.end());
for(int j=; j<it->second.size(); j++)
cout<<setfill('')<<setw()<<it->second[j]<<endl;
continue;
} it = press.find(queryText);
if(it != press.end())
{
cout<<query<<endl;
sort(it->second.begin(), it->second.end());
for(int j=; j<it->second.size(); j++)
cout<<setfill('')<<setw()<<it->second[j]<<endl;
continue;
} it = year.find(queryText);
if(it != year.end())
{
cout<<query<<endl;
sort(it->second.begin(), it->second.end());
for(int j=; j<it->second.size(); j++)
cout<<setfill('')<<setw()<<it->second[j]<<endl;
continue;
} //未找到
cout<<query<<endl<<"Not Found"<<endl;
} return ;
}
pat 1022 digital library的更多相关文章
- PAT 1022 Digital Library[map使用]
1022 Digital Library (30)(30 分) A Digital Library contains millions of books, stored according to th ...
- 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 ...
- 1022 Digital Library——PAT甲级真题
1022 Digital Library A Digital Library contains millions of books, stored according to their titles, ...
- 1022 Digital Library (30 分)
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 ...
- 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 ...
随机推荐
- 浅谈Android的广告欢迎界面(倒计时)
前些时候就是别人问我他的android APP怎么做一个广告的欢迎界面,就是过几秒后自动跳转到主界面的实现. 也就是下面这种类似的效果.要插什么广告的话你就换张图吧. 那么我就思考了下,就用了andr ...
- k-vim常见快捷键
前段时间看到wklken分享的k-vim配置,试用了下真的爽到飞起. 不过唯一不爽的是有一些快捷键一直记不住,现在整理些常用的快捷键,以备查阅. F2 set nu/nonu,行号开关,用于鼠标复制代 ...
- Maven02——回顾、整合ssh框架、分模块开发、私服
1 回顾 1.1 Maven的好处 节省空间 对jar包做了统一管理 依赖管理 一键构建 可跨平台 应用在大型项目可提高开发效率 1.2 Maven安装部署配置 1.3 Maven的仓库 本地仓库 远 ...
- sqlmap完成简单的sql注入
扫描目标站点,是否存在注入 --users获取用户名 --dump --tables探测表和数据库信息 跑出来的字段 admin --dump -T admin -C admin,password暴库 ...
- Maven(三)在Eclipse中使用Maven与Maven坐标
这一篇讲解一下在eclipse中使用maven,在一些高版本的eclipse中是自带maven插件的.所以这里就不在讲解怎么安装插件了. 接下来我们创建一个MavenFirst项目 一.在Eclips ...
- CTF---密码学入门第一题 这里没有key
这里没有key分值:10 来源: 西普学院 难度:易 参与人数:5577人 Get Flag:1965人 答题人数:2074人 解题通过率:95% 你说没有就没有啊,俺为啥要听你的啊 解题链接: ht ...
- BZOJ:3911: SGU383 Caravans(三角剖分)
原题链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3911 直接求最小生成树显然边太多,考虑少用点边. 连出来的边肯定是没相交的,我们需要做一下 ...
- XYZZY(spfa求最长路)
http://acm.hdu.edu.cn/showproblem.php?pid=1317 XYZZY Time Limit: 2000/1000 MS (Java/Others) Memor ...
- 了解前端中的SPA
单页Web应用(single page web application,SPA),就是只有一张Web页面的应用,是加载单个HTML 页面并在用户与应用程序交互时动态更新该页面的Web应用程序. 单页W ...
- js时间戳与时间日期间相互转换
今天在工作中要将获取到的时间转换为时间戳,一时间竟不知道怎么用,于是不得不去查询资料,这里特地做个笔记. 1.将日期转换为时间戳. 要将日期转换为时间戳,首先得先获取到日期,这里可以直接指定日期,或者 ...