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 ...
随机推荐
- linq中的分组和排序
一.分组 group 组内成员 by 分组条件 into 组的信息 class Program { static void Main(string[] args) { string[] name = ...
- AVFoundation(二)---MPMusicPlayerController
话不多说,直接上代码,代码中详细介绍了如何初始化,并设置一些常用的属性. /** * MPMusicPlayerController用于播放音乐库中的音乐 */ /** * 初始化MPMusicPla ...
- FreeRTOS中断优先级配置(重要)
FreeRTOS中断优先级配置(重要) 本章节为大家讲解FreeRTOS中断优先级配置,此章节非常重要,初学者经常在这里犯迷糊.对于初学者来说,本章节务必要整明白.12.1 NVIC基础知识12.2 ...
- 解决centos无法上传文件和打开文件夹
使用yum搭建了ftp服务..yum的使用参考:http://blog.csdn.net/enson16855/article/details/9140623 windows使用FileZilla连接 ...
- HDU<1372>/bfs
题目连接 简单bfs搜索 #include <set> #include <map> #include <cmath> #include <queue> ...
- hdu 2544 最短路 (spfa)
最短路 Time Limit : 5000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Submissio ...
- UVALive 2056 Lazy Math Instructor(递归处理嵌套括号)
因为这个题目说明了优先级的规定,所以可以从左到右直接运算,在处理嵌套括号的时候,可以使用递归的方法,给定每一个括号的左右边界,伪代码如下: int Cal(){ if(括号) sum += Cal( ...
- Java中域 实例域 静态域
1.java中的域 所谓的域,翻译成英文就是field, 也就是我们常说的字段,或者说是属性. 比如类的字段(属性),局部的,全局的.所谓域,其实是“field”的翻译 然后实例域,就是 实例(&qu ...
- 高性能IO模型浅析(转)
转自:http://www.cnblogs.com/fanzhidongyzby/p/4098546.html 是我目前看到的解释IO模型最清晰的文章,当然啦,如果想要详细的进一步了解还是继续啃蓝宝书 ...
- Chapter 1 First Sight——14
I parked in front of the first building, which had a small sign over the door reading front office. ...