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 ...
随机推荐
- [PHP] PHP源码中的条件编译定义
根据不同情况编译不同代码.产生不同目标文件的机制,称为条件编译有这些预处理命令:#if.#elif.#else #endif :#ifdef #else #endif PHP源码: #ifdef SE ...
- 云计算之路-阿里云上:docker swarm 集群故障与异常
在上次遭遇 docker swarm 集群故障后,我们将 docker 由 17.10.0-ce 升级为最新稳定版 docker 17.12.0-ce . 前天晚上22:00之后集群中的2个节点突然出 ...
- async/await 执行顺序详解
随着async/await正式纳入ES7标准,越来越多的人开始研究据说是异步编程终级解决方案的 async/await.但是很多人对这个方法中内部怎么执行的还不是很了解,本文是我看了一遍技术博客理解 ...
- poj 1743
Musical Theme Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 24835 Accepted: 8377 De ...
- bzoj 1705;poj 3612:[Usaco2007 Nov]Telephone Wire 架设电话线
Description 最近,Farmer John的奶牛们越来越不满于牛棚里一塌糊涂的电话服务 于是,她们要求FJ把那些老旧的电话线换成性能更好的新电话线. 新的电话线架设在已有的N(2 <= ...
- codeforces 767A Snacktower(模拟)
A. Snacktower time limit per test:2 seconds memory limit per test:256 megabytes input:standard input ...
- HTML5 Canvas 数据持久化存储之属性列表
属性列表想必大家都不会陌生,正常用 HTML5 来做的属性列表大概就是用下拉菜单之类的,而且很多情况下,下拉列表还不够好看,怎么办?我试着用 HT for Web 来实现属性栏点击按钮弹出多功能选框, ...
- Oracle:对用户的CREATE、ALTER、GRANT、REVOKE操作练习
--创建一个用户yong2,yong2的表空间为users,临时表空间为temp,users的表空间大小为10M,密码立刻过期,用户锁定. CREATE USER yong2IDENTIFIED BY ...
- ThinkPHP5+小程序商城 网盘视频
ThinkPHP5+小程序商城 网盘视频 有需要联系我 QQ:1844912514
- DESTOON B2B标签(tag)调用手册
路径:include/tag.func.php 1.标签格式的大致说明 {tag("moduleid=9&table=article_9&length=40&cond ...