【PAT甲级】1022 Digital Library (30 分)(模拟)
题意:
输入一个正整数N(<=10000),接下来输入N组数据,ID,书名,作者,关键词,出版社,出版年份。
然后输入一个正整数M(<=1000),接下来输入查询的数据,递增输出ID,若没有查找到则输出Not Found。
trick:
第三组数据中会有需要补0的ID,建议采用printf("%07d",ID)输出。
AAAAAccepted code:
#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
typedef struct book{
int ID;
char name[];
char writer[];
char words[][];
char publisher[];
char year[];
int length[];
int wordlength[];
};
book b[];
char s[];
bool cmp(book x,book y){
if(x.ID!=y.ID)
return x.ID<y.ID;
}
int main(){
int n;
scanf("%d",&n);
for(int i=;i<=n;++i){
scanf("%d",&b[i].ID);
char x=;
int tt=;
int tot=;
getchar();
while(){
scanf("%c",&x);
if(x=='\n')
break;
b[i].name[tot++]=x;
}
b[i].length[]=tot;
x=;
tt=;
tot=;
while(){
scanf("%c",&x);
if(x=='\n')
break;
b[i].writer[tot++]=x;
}
b[i].length[]=tot;
x=;
tt=;
tot=;
while(){
scanf("%c",&x);
if(x=='\n')
break;
else if(x==' '){
b[i].wordlength[tot]=tt;
++tot;
tt=;
}
else
b[i].words[tot][tt++]=x;
}
b[i].wordlength[tot]=tt;
b[i].length[]=tot;
tot=;
x=;
tt=;
while(){
scanf("%c",&x);
if(x=='\n')
break;
b[i].publisher[tot++]=x;
}
b[i].length[]=tot;
x=;
tt=;
tot=;
while(){
scanf("%c",&x);
if(x=='\n')
break;
b[i].year[tot++]=x;
}
b[i].length[]=tot;
}
sort(b+,b++n,cmp);
/*
for(int i=1;i<=n;++i){
cout<<b[i].ID<<"\n";
cout<<b[i].name<<"\n";
cout<<b[i].writer<<"\n";
for(int j=0;j<=b[i].length[3];++j)
cout<<b[i].words[j]<<"\n";
cout<<b[i].publisher<<"\n";
cout<<b[i].year<<"\n";
for(int j=1;j<5;++j)
cout<<b[i].length[j]<<"\n";
}
*/
int m;
scanf("%d",&m);
for(int i=;i<=m;++i){
memset(s,,sizeof(s));
if(i==)
getchar();
int cnt=;
char xx=;
int tot=;
while(){
scanf("%c",&xx);
if(xx=='\n')
break;
s[tot++]=xx;
}
printf("%s\n",s);
int len=tot;
int x=s[]-'';
for(int j=;j<=n;++j){
int flag=;
if(len<)
continue;
if(x==){
if(len-==b[j].length[]){
for(int l=;l<len;++l)
if(b[j].name[l-]!=s[l]){
flag=;
break;
}
}
else
flag=;
}
else if(x==){
if(len-==b[j].length[]){
for(int l=;l<len;++l)
if(b[j].writer[l-]!=s[l]){
flag=;
break;
}
}
else
flag=;
}
else if(x==){
for(int l=;l<=b[j].length[];++l)
if(len-==b[j].wordlength[l]){
for(int h=;h<len;++h)
if(b[j].words[l][h-]!=s[h]){
flag++;
break;
}
}
else
flag++;
}
else if(x==){
if(len-==b[j].length[]){
for(int l=;l<len;++l)
if(b[j].publisher[l-]!=s[l]){
flag=;
break;
}
}
else
flag=;
}
else if(x==){
if(len-==b[j].length[]){
for(int l=;l<len;++l)
if(b[j].year[l-]!=s[l]){
flag=;
break;
}
}
else
flag=;
}
if(x==&&flag<b[j].length[]+||x!=&&!flag){
++cnt;
printf("%07d\n",b[j].ID);
}
}
if(!cnt)
printf("Not Found\n");
}
return ;
}
【PAT甲级】1022 Digital Library (30 分)(模拟)的更多相关文章
- PAT 甲级 1022 Digital Library (30 分)(字符串读入getline,istringstream,测试点2时间坑点)
1022 Digital Library (30 分) A Digital Library contains millions of books, stored according to thei ...
- pat 甲级 1022. Digital Library (30)
1022. Digital Library (30) 时间限制 1000 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A Di ...
- 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 分)
1022 Digital Library (30 分) A Digital Library contains millions of books, stored according to thei ...
- PAT 甲级 1022 Digital Library
https://pintia.cn/problem-sets/994805342720868352/problems/994805480801550336 A Digital Library cont ...
- PAT A 1022. Digital Library (30)【结构体排序检索】
https://www.patest.cn/contests/pat-a-practise/1022 直接模拟, 输入,按id排序,检索 #include <iostream> #incl ...
- PAT甲级1022 Digital Library
题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805480801550336 题意: 每一本书有一个id, 书名,作 ...
- PAT 甲级 1080 Graduate Admission (30 分) (简单,结构体排序模拟)
1080 Graduate Admission (30 分) It is said that in 2011, there are about 100 graduate schools ready ...
- 1022 Digital Library (30)(30 分)
A Digital Library contains millions of books, stored according to their titles, authors, key words o ...
随机推荐
- weinre 真机调试
1.在任意文件夹 安装weinre cnpm -g install weinre 2.启动 weinre --httpPort 8009 --boundHost -all- 3.在你的页面中加入 本机 ...
- Centos6.10-FastDFS-Tracker-Nginx示例配置
nginx 安装过程<详见> 1.进入工作目录 cd /usr/local/nginx/conf 2.创建子目录 mkdir configs 3.创建storage代理配置 cd conf ...
- C:字符数组 与 字符串
字符串与字符数组 C语言中没有字符串这种数据类型,可以通过char的数组来替代: 字符串一定是一个char的数组,但char的数组未必是字符串: 数字0(和字符'\0'等价)结尾的char数组就是一个 ...
- UVA10600 ACM Contest and Blackout
用prim算法求最小生成树和次小生成树~ #include<cstdio> #include<algorithm> #include<cstring> using ...
- java平衡二叉树AVL数
平衡二叉树(Balanced Binary Tree)具有以下性质:它是一棵空树或它的左右两个子树的高度差的绝对值不超过1,并且左右两个子树都是一棵平衡二叉树 右旋:在插入二叉树的时候,根节点的右侧高 ...
- django.db.utils.OperationalError: (2003, "Can't connect to MySQL server on ‘127.0.0.1’)
报错信息如下: 检查发现原来是自己的sql没有启动 启动mysql后,
- EF中 GroupJoin 与 Join
数据: GroupJoin: 返回左表所有数据 using (tempdbEntities context = new tempdbEntities()) { var query = context. ...
- angular9 学习笔记
前言: AngularJS作为Angular的最早版本,2010年发布其初始版本,至今已经10年了.除了这个最初版本(没学过),项目上一直从2.x 到至今项目使用8.x版本,现在Angular在201 ...
- 【笔记8-Redis分布式锁】从0开始 独立完成企业级Java电商网站开发(服务端)
Redis分布式锁 Redis分布式锁命令 setnx当且仅当 key 不存在.若给定的 key 已经存在,则 setnx不做任何动作.setnx 是『set if not exists』(如果不存在 ...
- Fluent_Python_Part4面向对象,10-seq-hacking,序列的修改、散列和切片
第四部分第10章,序列的修改.散列和切片 中文电子书P423 这一章接第1章.第9章,以第9章定义的Vector2d类为基础,定义表示多为向量的Vector类.这个类的行为与Python中标准的不可变 ...