这里提供两种写法, 其实都是一样的,第一种比较快。

#include <bits/stdc++.h>
using namespace std; map<string,set<string> > mp[6]; int main()
{
//freopen("in.txt","r",stdin);
ios::sync_with_stdio(false);
int N;
cin>>N;
cin.get();
string ID,auth,title,puber,keywords,year;
for (int i=0;i<N;i++) {
getline(cin,ID);
getline(cin,title);
mp[1][title].insert(ID);
getline(cin,auth);
mp[2][auth].insert(ID);
getline(cin,keywords);
stringstream ss(keywords);
string key;
while (ss>>key) {
mp[3][key].insert(ID);
}
getline(cin,puber);
mp[4][puber].insert(ID);
getline(cin,year);
mp[5][year].insert(ID);
// cout<<ID<<title<<auth<<keywords<<puber<<year<<endl;
}
int M;
cin>>M;
int num;
string query;
for (int i=0;i<M;i++) {
cin>>num;
cin.get();
cin.get();
getline(cin,query); set<string> ans=mp[num][query];
cout<<num<<": "<<query<<endl;
if (ans.empty())
cout<<"Not Found"<<endl;
else
for (set<string>::iterator it=ans.begin();it!=ans.end();it++) cout<<*it<<endl;
}
return 0;
}

第二种:

#include <bits/stdc++.h>
using namespace std; map<pair<int,string>,set<string> >mp; int main()
{
// freopen("in.txt","r",stdin);
ios::sync_with_stdio(false);
int N;
cin>>N;
cin.get();
string title,author,key,puber,year,ID;
for (int i=0;i<N;i++) {
getline(cin,ID);
getline(cin,title);
mp[make_pair(1,title)].insert(ID);
getline(cin,author);
mp[make_pair(2,author)].insert(ID);
getline(cin,key);
stringstream ss(key);
string tmp;
while (ss>>tmp) {
mp[make_pair(3,tmp)].insert(ID);
}
getline(cin,puber);
mp[make_pair(4,puber)].insert(ID);
getline(cin,year);
mp[make_pair(5,year)].insert(ID);
// cout<<ID<<" "<<title<<" "<<author<<" "<<key<<" "<<puber<<" "<<year<<endl;
}
int M;
cin>>M;
int n;
string query;
for (int i=0;i<M;i++) {
cin>>n;
cin.get();
cin.get();
getline(cin,query);
// cout<<n<<query<<endl;
set<string> ans=mp[make_pair(n,query)];
cout<<n<<": "<<query<<endl;
if (ans.empty()) {
cout<<"Not Found"<<endl;
}
else {
for (set<string>::iterator it=ans.begin();it!=ans.end();it++) {
cout<<*it<<endl;
}
} }
return 0;
}

1022_Digital_Library (30分)的更多相关文章

  1. PTA 07-图5 Saving James Bond - Hard Version (30分)

    07-图5 Saving James Bond - Hard Version   (30分) This time let us consider the situation in the movie ...

  2. PTA 社交网络图中结点的“重要性”计算(30 分)

    7-12 社交网络图中结点的“重要性”计算(30 分) 在社交网络中,个人或单位(结点)之间通过某些关系(边)联系起来.他们受到这些关系的影响,这种影响可以理解为网络中相互连接的结点之间蔓延的一种相互 ...

  3. L3-015 球队“食物链” (30 分)

    L3-015 球队“食物链” (30 分)   某国的足球联赛中有N支参赛球队,编号从1至N.联赛采用主客场双循环赛制,参赛球队两两之间在双方主场各赛一场. 联赛战罢,结果已经尘埃落定.此时,联赛主席 ...

  4. PAT A1127 ZigZagging on a Tree (30 分)——二叉树,建树,层序遍历

    Suppose that all the keys in a binary tree are distinct positive integers. A unique binary tree can ...

  5. 04-树6 Complete Binary Search Tree(30 分)

    title: 04-树6 Complete Binary Search Tree(30 分) date: 2017-11-12 14:20:46 tags: - 完全二叉树 - 二叉搜索树 categ ...

  6. PTA 7-2 二叉搜索树的结构(30 分)

    7-2 二叉搜索树的结构(30 分) 二叉搜索树或者是一棵空树,或者是具有下列性质的二叉树: 若它的左子树不空,则左子树上所有结点的值均小于它的根结点的值:若它的右子树不空,则右子树上所有结点的值均大 ...

  7. 1127 ZigZagging on a Tree (30 分)

    1127 ZigZagging on a Tree (30 分) Suppose that all the keys in a binary tree are distinct positive in ...

  8. 【PAT】1053 Path of Equal Weight(30 分)

    1053 Path of Equal Weight(30 分) Given a non-empty tree with root R, and with weight W​i​​ assigned t ...

  9. 【PAT】1091 Acute Stroke(30 分)

    1091 Acute Stroke(30 分) One important factor to identify acute stroke (急性脑卒中) is the volume of the s ...

随机推荐

  1. mybatis(五):源码分析 - config文件加载流程

    详细的可以参考https://blog.csdn.net/weixin_33850890/article/details/88112849

  2. 02 Django虚拟环境搭建

    01 创建虚拟环境目录 该目录用于存放所有虚拟环境. cd / mkdir venv cd venv 02 创建当前项目的虚拟环境 virtualenv --python=/usr/bin/pytho ...

  3. nginx下载,安装,基础命令,和代理tomcat例子理解

    nginx代理讲的很好理解:https://www.cnblogs.com/ysocean/p/9392908.html 一.nginx应用场景: 1.反向代理(用的非常多) 客户端发出请求,反向代理 ...

  4. 记录 shell学习过程(1) 超简单的面向过程的2个shell 分区以及创建lvm

    分区 #!/usr/bin/env bash #fdisk /dev/sdb << EOF #n # # # #+600M #w #EOF 创建lvm pvcreate /dev/sdb ...

  5. 后台异常 - sql语句查询出的结果与dao层返回的结果不一致

    问题描述 sql语句查询出的结果与dao层返回的结果不一致 问题原因 (1)select 中,查询的列名称重复,数据出现错乱 (2)使用不等号,不等号(!=,<>),查询出来的结果集不包含 ...

  6. kmp算法散记

    1. https://blog.csdn.net/abcjennifer/article/details/5794547 #include<bits/stdc++.h> using nam ...

  7. Python_内置函数和匿名函数

    楔子 在讲新知识之前,我们先来复习复习函数的基础知识. 问:函数怎么调用? 函数名() 如果你们这么说...那你们就对了!好了记住这个事儿别给忘记了,咱们继续谈下一话题... 来你们在自己的环境里打印 ...

  8. 【sql】sql必知必会_02

    chapter10 - 常用的sql标准有哪些,在SQL92中是如何使用连接的? sql两个主要的标准sql92.sql95: sql92中的五种连接方式: a.笛卡尔积:是一个数学运算,两个集合X和 ...

  9. Android开发实战——记账本(4)

    开发日志(4)——MainActivity 在MainActivity中编写了几个方法.首先,点击账本的一条记录可以选择删除他,然后重写了fab,使之在点击他后能够添加记录.还写了删除全部记录的方法. ...

  10. 【音乐欣赏】《紅蓮華》 - LiSA

    曲名:紅蓮華 作者:LiSA [00:00.92]強くなれる理由を知った [00:07.34]僕を連れて 進め [00:18.74]泥だらけの走馬灯に酔う [00:24.37]強張る心 震える手は [ ...