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 ...
随机推荐
- DM642学习:CMD、GEL文件
在建立ccs工程的时候,cmd文件和gel文件非常重要,如不能配置好会出现一些莫名其妙的问题. 1. CMD文件: 不同的DSP芯片内集成的存储器大小各异,但其配置方式是类似的.大家可通过查阅DSP芯 ...
- document.getElementById("id").value与$("#id").val()之间的区别
本文链接:https://blog.csdn.net/mottohlm/article/details/78364196....今天在项目中遇到这么一个JS报错:原因是代码中有这么一段:对,就是var ...
- NetMQ用作IPC的实例
发送端/接收端 using System; using System.Threading; using NetMQ; using NetMQ.Sockets; namespace NetMQIPCSe ...
- goland 2019.1.1破解
https://blog.csdn.net/hi_liuxiansheng/article/details/89078405
- 在EF中使用原生SQL,首先要创建上下文对象
using (var db = new Entities()) { //数据操作 } 新增 string sql = "insert into UserInfo values('zhangs ...
- 2.2 logistic回归损失函数(非常重要,深入理解)
上一节当中,为了能够训练logistic回归模型的参数w和b,需要定义一个成本函数 使用logistic回归训练的成本函数 为了让模型通过学习来调整参数,要给出一个含有m和训练样本的训练集 很自然的, ...
- day11 ss命令 查看网络端口使用情况及对应pid centos7
[root@oldboyedu ~]# ss -lntup Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port udp UNC ...
- Android 使用 MPAndroidChart 实现折线图
Android 使用 MPAndroidChart 实现折线图 做Android项目的时候用到了折线图,不光折线图,还可能遇到很多的图表需要展示渲染,自己手画的话那好玩了,今天使用MPAndroidC ...
- Android Socket 通信
Android socket 通信 安卓编写Socket客户端,实现连接Socket服务端通信. 创建Socket连接并获取服务端数据 先创建几个全局变量吧 private BufferedWrite ...
- 使用VS2017开发安卓app(2)新建项目
安装完成后,在c#下找到Android,选择Android应用(Xamarin),修改项目名称和路径,新建第一个安卓项目! 点击确定后会出现 这里我们选择空白应用和Android 7.1. 创建新项目 ...