1022_Digital_Library (30分)
这里提供两种写法, 其实都是一样的,第一种比较快。
#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分)的更多相关文章
- 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 ...
- PTA 社交网络图中结点的“重要性”计算(30 分)
7-12 社交网络图中结点的“重要性”计算(30 分) 在社交网络中,个人或单位(结点)之间通过某些关系(边)联系起来.他们受到这些关系的影响,这种影响可以理解为网络中相互连接的结点之间蔓延的一种相互 ...
- L3-015 球队“食物链” (30 分)
L3-015 球队“食物链” (30 分) 某国的足球联赛中有N支参赛球队,编号从1至N.联赛采用主客场双循环赛制,参赛球队两两之间在双方主场各赛一场. 联赛战罢,结果已经尘埃落定.此时,联赛主席 ...
- 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 ...
- 04-树6 Complete Binary Search Tree(30 分)
title: 04-树6 Complete Binary Search Tree(30 分) date: 2017-11-12 14:20:46 tags: - 完全二叉树 - 二叉搜索树 categ ...
- PTA 7-2 二叉搜索树的结构(30 分)
7-2 二叉搜索树的结构(30 分) 二叉搜索树或者是一棵空树,或者是具有下列性质的二叉树: 若它的左子树不空,则左子树上所有结点的值均小于它的根结点的值:若它的右子树不空,则右子树上所有结点的值均大 ...
- 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 ...
- 【PAT】1053 Path of Equal Weight(30 分)
1053 Path of Equal Weight(30 分) Given a non-empty tree with root R, and with weight Wi assigned t ...
- 【PAT】1091 Acute Stroke(30 分)
1091 Acute Stroke(30 分) One important factor to identify acute stroke (急性脑卒中) is the volume of the s ...
随机推荐
- PyCharm专业版2019.3.2激活码到期2089年!!!
Pycharm是一款很好用的python开发工具,开发Python爬虫和Python web方面都很不错 这里我为大家提供了pycharm激活方式2089年(都支持PyCharm20 激活步骤如下: ...
- vue -bug1
打包问题: 1.在终端用 npm run build 如果想要在本地资源也能访问 2.npm install -g http-server 3.配置好如下 3.1 config->index. ...
- JS 获取随机颜色值
获取随机颜色值 function fn1(){ return '#' + Math.floor( Math.random() * 0xffffff ).toString(16); } function ...
- Having用法以及其和Where区别
例如,进行分组语句: select year,count(id) num from tblPlantProduce group by year 在这条语句中若要筛选出年份>2005年的有两种方式 ...
- mockito使用教程
一.什么是 Mock 测试 Mock 测试就是在测试过程中,对于某些不容易构造(如 HttpServletRequest 必须在Servlet 容器中才能构造出来)或者不容易获取比较复杂的对象(如 J ...
- EAC3 Adaptive Hybrid Transform (AHT)
adaptive hybrid transform 由两个linear transforms级联组成. 第一个transform为MDCT,MDCT使用KBD window产生256个transfor ...
- 浅谈Power Signoff
Power Analysis是芯片设计实现中极重要的一环,因为它直接关系到芯片的性能和可靠性.Power Analysis 需要Timing Analysis 产生包含频率.transition 等时 ...
- Service Worker,Web Worker,WebSocket的对比
Service Worker 处理网络请求的后台服务.适用于离线和后台同步数据或推送信息.不能直接和dom交互.通过postMessage方法交互. Web Worker 模拟多线程,允许复杂计算功能 ...
- c++对象的内存模式
#include <iostream> using namespace std; class Obj { private: int* a; public: int* ga() { retu ...
- C语言程序设计100例之(28):直线蛇形阵
例28 直线蛇形阵 问题描述 编写程序,将自然数1.2.….N2按蛇形方式逐个顺序存入N阶方阵.例如,当N=3和N=4时的直线蛇形阵如下图1所示. 图1 直线蛇形阵 输入格式 一个正整 ...