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

#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. 数据从mmsql导入mysql

    SQL SERVER数据导入MYSQL 工具: navicat for mysql 百度搜一个安装就可以,前提是你已经安装了mysql 1,创建目标数据库 点击创建好的目标数据库website点的表一 ...

  2. Redis事务实现原理

    一:简介 Redis事务通常会使用MULTI,EXEC,WATCH等命令来完成,redis实现事务实现的机制与常见的关系型数据库有很大的却别,比如redis的事务不支持回滚,事务执行时会阻塞其它客户端 ...

  3. Windows常用批处理命令 CMD BAT (CMD目录操作等dir)

    Windows常用批处理 CMD BAT CMD获取文件夹下所有文件的名称并打印(输出)到指定目录 dir C:\Users\\Desktop\png\*.*/s >c:\.txt //cmd ...

  4. MySQL | 查看log日志

    1. 进入mysql mysql -u用户名 -p密码 2. 开启日志 et global general_log=on: 3. 查看mysql日志文件的路径 show variables like ...

  5. VS2017连接MySQL数据库

    vs默认无法直接连接mysql,需要我们自己配置环境. 1.下载mysql-installer-community-8.0.18.0.msi 下载地址:https://dev.mysql.com/do ...

  6. java.awt.Font

    显示效果 Font mf = new Font(String 字体,int 风格,int 字号);字体:TimesRoman, Courier, Arial等风格:三个常量 lFont.PLAIN, ...

  7. Java必须知道的知识点

    junit用法,before,beforeClass,after, afterClass的执行顺序 分布式锁 nginx的请求转发算法,如何配置根据权重转发 用hashmap实现redis有什么问题( ...

  8. XPath注入

    XPath基础 XPath 即为 XML 路径语言,是一门在XML文档中查找信息的语言.XPath 基于 XML 的树状结构,有不同类型的节点,包括元素节点,属性节点和文本节点,提供在数据结构树中找寻 ...

  9. 2019-08-05 纪中NOIP模拟B组

    T1 [JZOJ1432] 输油管道 题目描述 请你帮忙设计一个从城市M到城市Z的输油管道,现在已经把整个区域划分为R行C列,每个单元格可能是空的也可能是以下7种基本管道之一: 油从城市M流向Z,‘+ ...

  10. C++-POJ1200-Crazy Search[hash]

    由于已经给出字符只有NC种,故可以把子串视为一个NC进制的数,以此构造hash函数就可以了 #include <set> #include <map> #include < ...