#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的更多相关文章

  1. PAT 1022 Digital Library[map使用]

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

  2. pat 甲级 1022. Digital Library (30)

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

  3. PAT 甲级 1022 Digital Library (30 分)(字符串读入getline,istringstream,测试点2时间坑点)

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

  4. 1022 Digital Library——PAT甲级真题

    1022 Digital Library A Digital Library contains millions of books, stored according to their titles, ...

  5. 1022 Digital Library (30 分)

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

  6. PAT 甲级 1022 Digital Library

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

  7. PAT Advanced 1022 Digital Library (30 分)

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

  8. 1022. Digital Library (30)

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

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

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

随机推荐

  1. hdu 6191--Query on A Tree(持久化字典树)

    题目链接 Problem Description Monkey A lives on a tree, he always plays on this tree. One day, monkey A l ...

  2. JavaScript拆分字符串并将分割的数据放到数组中

    1 2 3 4 5 6 7 var splitArray = new Array(); var string="太平洋.大西洋.印度洋.北冰洋"; var regex = /./; ...

  3. 【WC2013】糖果公园

    Candyland 有一座糖果公园,公园里不仅有美丽的风景.好玩的游乐项目,还有许多免费糖果的发放点,这引来了许多贪吃的小朋友来糖果公园玩. 糖果公园的结构十分奇特,它由 nn 个游览点构成,每个游览 ...

  4. 最长上升子序列(LIS) dp学习~3

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1087 Super Jumping! Jumping! Jumping! Time Limit: 200 ...

  5. eclipse(Version: Mars.2 Release (4.5.2)) groovy plugin install process.

    There are two way to install : First: 1.check your eclipse version:Help-->About Eclipse 2.open He ...

  6. svn过滤文件配置

    ---恢复内容开始--- 在 在输入框中输入这个即可..... .classpath .project .springBeans *.class *.o *.lo *.la *.al .libs *. ...

  7. Python scrapy------分类获取美团整站数据

    欢迎联系讨论:qq:1170370113 以下是我们获取美团页面的城市信息 获取到了城市信息以后我们可以进行分类保存,以便于后续能够分类获取数据 获取我们需要城市的景区的所有相关id并且进行保存 最后 ...

  8. 【django基础之ORM】

    一.定义 1.什么是ORM? ORM,即Object-Relational Mapping(对象关系映射),它的作用是在关系型数据库和业务实体对象之间作一个映射,这样,我们在具体的操作业务对象的时候, ...

  9. WaitForXXX等待无效句柄

    =================================版权声明================================= 版权声明:原创文章 禁止转载  请通过右侧公告中的“联系邮 ...

  10. Android之MaterialDesign应用技术

    PS:纵观现在大大小小软件的界面都变的比较漂亮,还有一些系统了,比如小米的MIUI,华为的EMUI等,虽然底层都是安卓,但他们的界面多多少少都会不同,谷歌对这个UI也是非常重视的,MaterialDe ...