PAT (Advanced Level) 1022. Digital Library (30)
简单模拟题。
写的时候注意一些小优化,小心TLE。
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<map>
#include<queue>
#include<vector>
using namespace std; struct X
{
string id;
char title[]; int Title;
char author[]; int Author;
vector<int>key;
char publisher[]; int Publisher;
int year;
}s[+];
int n,m; map<string,int>Tit,Aut,Key,Pub;
vector<string>ans;
int tot_Tit=,tot_Aut=,tot_Key=,tot_Pub=; bool cmp(const X&a,const X&b)
{
return a.id<b.id;
} int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
{
cin>>s[i].id; getchar();
gets(s[i].title); if(Tit[s[i].title]==) Tit[s[i].title]=++tot_Tit; s[i].Title=Tit[s[i].title];
gets(s[i].author); if(Aut[s[i].author]==) Aut[s[i].author]=++tot_Aut; s[i].Author=Aut[s[i].author];
char tmp[]; gets(tmp);
int len=strlen(tmp);
string q;
for(int j=;j<=len;j++)
{
if(tmp[j]==' '||tmp[j]=='\0')
{
if(Key[q]==) Key[q]=++tot_Key;
s[i].key.push_back(Key[q]);
q.clear();
}
else q=q+tmp[j];
}
gets(s[i].publisher); if(Pub[s[i].publisher]==) Pub[s[i].publisher]=++tot_Pub; s[i].Publisher=Pub[s[i].publisher];
scanf("%d",&s[i].year);
} sort(s+,s++n,cmp); scanf("%d",&m);
for(int i=;i<=m;i++)
{
char op[]; scanf("%s",op); getchar();
char h[]; gets(h);
printf("%s %s\n",op,h); if(op[]=='')
{
int num=Tit[h];
for(int i=;i<=n;i++)
if(s[i].Title==num) ans.push_back(s[i].id);
}
else if(op[]=='')
{
int num=Aut[h];
for(int i=;i<=n;i++)
if(s[i].Author==num) ans.push_back(s[i].id);
}
else if(op[]=='')
{
int num=Key[h];
for(int i=;i<=n;i++)
{
for(int j=;j<s[i].key.size();j++)
{
if(s[i].key[j]==num)
{
ans.push_back(s[i].id);
break;
}
}
}
}
else if(op[]=='')
{
int num=Pub[h];
for(int i=;i<=n;i++)
if(s[i].Publisher==num) ans.push_back(s[i].id);
}
else if(op[]=='')
{
int num=;
for(int i=;h[i];i++) num=num*+h[i]-'';
for(int i=;i<=n;i++)
if(s[i].year==num) ans.push_back(s[i].id);
}
if(ans.size()==) printf("Not Found\n");
else
{
for(int i=;i<ans.size();i++) cout<<ans[i]<<endl;
ans.clear();
}
}
return ;
}
PAT (Advanced Level) 1022. Digital Library (30)的更多相关文章
- PTA (Advanced Level) 1022 Digital Library
Digital Library A Digital Library contains millions of books, stored according to their titles, auth ...
- 【PAT甲级】1022 Digital Library (30 分)(模拟)
题意: 输入一个正整数N(<=10000),接下来输入N组数据,ID,书名,作者,关键词,出版社,出版年份. 然后输入一个正整数M(<=1000),接下来输入查询的数据,递增输出ID,若没 ...
- pat 甲级 1022. Digital Library (30)
1022. Digital Library (30) 时间限制 1000 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A Di ...
- PAT 甲级 1022 Digital Library (30 分)(字符串读入getline,istringstream,测试点2时间坑点)
1022 Digital Library (30 分) A Digital Library contains millions of books, stored according to thei ...
- 1022 Digital Library (30 分)
1022 Digital Library (30 分) A Digital Library contains millions of books, stored according to thei ...
- PAT Advanced 1022 Digital Library (30 分)
A Digital Library contains millions of books, stored according to their titles, authors, key words o ...
- 1022. Digital Library (30)
A Digital Library contains millions of books, stored according to their titles, authors, key words o ...
- 1022. Digital Library (30) -map -字符串处理
题目如下: A Digital Library contains millions of books, stored according to their titles, authors, key w ...
- 1022 Digital Library (30)(30 point(s))
problem A Digital Library contains millions of books, stored according to their titles, authors, key ...
随机推荐
- 使用SQLCMD在SQLServer执行多个脚本 转载
出处不明 概述: 作为DBA,经常要用开发人员提供的SQL脚本来更新正式数据库,但是一个比较合理的开发流程,当提交脚本给DBA执行的时候,可能已经有几百个sql文件,并且有执行顺序,如我现在工作的公司 ...
- C陷阱与缺陷 第二章
有关运算符优先级 1. "<<" 和 "+" data8 = data4H << 4 +data4L; 这里本意是让高四位的数据,左 ...
- 如何使用Android中的OpenGL ES媒体效果
引自:http://www.2cto.com/kf/201506/404366.html Android的媒体效果框架允许开发者可以很容易的应用多种令人印象深刻的视觉效果到照片或视频之上.作为这个媒体 ...
- CodeForces 709B Checkpoints 模拟
题目大意:给出n个点的坐标,和你当前的坐标,求走过n-1个点的最短路程. 题目思路:走过n-1个点,为了使路程更短,那么不走的点只可能第一个点或最后一个点.模拟就行了,比较恶心. #include&l ...
- input内文字点击消失 弹出层,可以写表单
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...
- Activity与Activity之间的传值
//----------Activity1中的布局--------------------------------- <LinearLayout xmlns:android="http ...
- ssh The authenticity of host 192.168.0.xxx can't be established
用ssh登录一个机器(换过ip地址),提示输入yes后,屏幕不断出现y,只有按ctrl + c结束 错误是:The authenticity of host 192.168.0.xxx can't b ...
- 5--OC--构造方法
// Created by Stephen on 16/3/2.// Copyright © 2016年 Stephen. All rights reserved.//// 回顾上一章节Perso ...
- html base1
标题: 标题(Heading)是通过 <h1> - <h6> 等标签进行定义的. <h1> 定义最大的标题.<h6> 定义最小的标题. 段落: < ...
- Python文件打包成EXE文件
工具:pyinstaller 安装:pip install pyinstaller 使用: 1 将依赖文件集中到一个文件夹: pyinstaller -D -w xxx.py ...