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 ... 
随机推荐
- 洛谷P1068 分数线划定
			https://www.luogu.org/problem/P1068 #include<bits/stdc++.h> using namespace std; struct Can { ... 
- js中迭代方法
			基础遍历数组: for() for( in ) for(var i = 0;i<arr.length;i++){ ... 
- Java上传图片到Ftp,包含上传后文件大小为0的问题和Properties配置文件的读取
			准备工作:需要使用coomos-net jar包.下载地址 一. 上传图片到FTP,文件大小为0的问题,解决:将ftp模式修改为Passive模式就可以了. //将ftp模式修改为Passive模式 ... 
- MySql -- unique唯一约束
			3.UNIQUE 约束 约束唯一标识数据库表中的每条记录. 创建一张测试表 CREATE TABLE `test`.`info`( `id` ) UNSIGNED NOT NULL AUTO_INCR ... 
- [IOI2002] 任务安排
			题目链接 题意 一些不能改变顺序的任务被分成若干批,每批包含相邻的若干任务.第 $i$ 个任务单独完成所需的时间是 $T_i$.在每批任务开始前,机器需要启动时间 $S$,而完成这批任务所需的时间是各 ... 
- (ghrd)pio设置
			设置中是下降沿,边沿触发. 
- 什么是文件的BOM头,及BOM头有哪些坑?
			1.什么是BOM? BOM是用来判断文本文件是哪一种Unicode编码的标记,其本身是一个Unicode字符("\uFEFF"),位于文本文件头部. 在不同的Unicode编码中, ... 
- 矩阵快速幂 裸 hdu1575
			裸题,求A^n次后的对角线数字之和 #include<cstdio> #include<algorithm> #include<string.h> using na ... 
- BZOJ 2342 [Shoi2011]双倍回文(Manacher)
			题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=2342 题意:求最长子串使得它有四个相同的回文串SSSS相连组成. 首先跑一边Manach ... 
- CentOS 7 使用笔记
			一.下载.解压或安装等命令: 目前自己用过的三个下载及安装命令:curl.wget.yum. yum用法: $ sudo yum install libpng16-1.6.29-alt1.i586.r ... 
