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 ...
随机推荐
- 0005 修改Django工程名
写框架非常耗时间,把框架写好以后,经测试稳定的框架,需要保存下来,以后有工程需要,直接更改工程名即可. 01 右键点击工程名,点击Refactor/Rename 02 选择更改工程名 03 关闭PyC ...
- 电脑进不去BIOS解决办法
把所有外设(主要是硬盘,包括装在主板上的固态硬盘)拆下来,拆下纽扣电池给主板放电,装回纽扣电池,重启F1进入BIOS. 最终查到原因,是固态那里出的问题,固态作为启动硬盘,被自己搞得有问题了,有两个启 ...
- 题解【洛谷P5958】[POI2017]Sabotaż
题面 考虑树形 \(\text{DP}\). 设 \(dp_i\) 为使 \(i\) 变成叛徒的最大值,同时 \(dp_i\) 也是使 \(i\) 不变成叛徒的最小值. 然后考虑如何转移状态. 如果 ...
- shiro认证和授权
一.shiro基础概念 Authentication:身份认证 / 登录,验证用户是不是拥有相应的身份: Authorization:授权,即权限验证,验证某个已认证的用户是否拥有某个权限:即判断用户 ...
- amazon 1
# 跨境电商 Amazon 丰富强大的海外站 开店流程 https://www.cifnews.com/article/48921 注册事项以及二审怎么过 https://www.cifnews.co ...
- vs2019 scanf 解决 C4996问题
1. 首先选择项目 2. 然后选择最下面那行的 工程属性, 其后于此处 3. 添加上 :_CRT_SECURE_NO_WARNINGS 最后保存,使用 scanf 读取即无报错了
- 手写基于Promise A+规范的Promise
const PENDING = 'pending';//初始态const FULFILLED = 'fulfilled';//初始态const REJECTED = 'rejected';//初始态f ...
- day11 ss命令 查看网络端口使用情况及对应pid centos7
[root@oldboyedu ~]# ss -lntup Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port udp UNC ...
- python修改文件后缀名
修改文件后缀名 # -*- coding: utf-8 -*- import os # # 列出当前目录下所有的文件 # filedir = 'C:\\Users\\WT\\Desktop\\test ...
- 题解【UVA12003】Array Transformer
题目描述 输入输出格式 输入格式 输出格式 输入输出样例 输入样例#1 10 1 11 1 2 3 4 5 6 7 8 9 10 2 8 6 10 输出样例#1 1 2 3 4 5 6 7 8 9 6 ...