题意:

输入一个正整数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 分)(模拟)的更多相关文章

  1. PAT 甲级 1022 Digital Library (30 分)(字符串读入getline,istringstream,测试点2时间坑点)

    1022 Digital Library (30 分)   A Digital Library contains millions of books, stored according to thei ...

  2. pat 甲级 1022. Digital Library (30)

    1022. Digital Library (30) 时间限制 1000 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A Di ...

  3. PAT Advanced 1022 Digital Library (30 分)

    A Digital Library contains millions of books, stored according to their titles, authors, key words o ...

  4. 1022 Digital Library (30 分)

    1022 Digital Library (30 分)   A Digital Library contains millions of books, stored according to thei ...

  5. PAT 甲级 1022 Digital Library

    https://pintia.cn/problem-sets/994805342720868352/problems/994805480801550336 A Digital Library cont ...

  6. PAT A 1022. Digital Library (30)【结构体排序检索】

    https://www.patest.cn/contests/pat-a-practise/1022 直接模拟, 输入,按id排序,检索 #include <iostream> #incl ...

  7. PAT甲级1022 Digital Library

    题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805480801550336 题意: 每一本书有一个id, 书名,作 ...

  8. PAT 甲级 1080 Graduate Admission (30 分) (简单,结构体排序模拟)

    1080 Graduate Admission (30 分)   It is said that in 2011, there are about 100 graduate schools ready ...

  9. 1022 Digital Library (30)(30 分)

    A Digital Library contains millions of books, stored according to their titles, authors, key words o ...

随机推荐

  1. SniperOJ-as fast as you can-Writeup

    SniperOJ-as fast as you can-Writeup 题目描述: 打开所给的题目地址 很容易可以看出这是一个简单的爬虫问题,爬去网页的信息并post,但在界面及网页源码中均没发现有价 ...

  2. 解决sublime不能正常使用python3中的input

    执行以下步骤 1.安装SublimeREPL插件 2.打开快捷键设置运行的快捷键 首选项->快捷设置 {"keys":["ctrl+y+h"], &quo ...

  3. Django框架之ORM常用字段

    一.ORM介绍 1.ORM概念 对象关系映射(Object Relational Mapping,简称ORM)模式是一种为了解决面向对象与关系数据库存在的互不匹配的现象的技术. 简单的说,ORM是通过 ...

  4. 让 typora和word一样好用

    让 typora和word一样好用  :https://github.com/itcastWsy/typora_copy_images typora是一款支持实时预览的markdown编辑器,作者在使 ...

  5. PHP加JS实现分片上传,断点续传

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"/> <title> ...

  6. 卫哲VS投行女,秋后算账是阿里的企业文化吗?

    编辑 | 于斌 出品 | 于见(mpyujian) 提到马云,大家都会想到淘宝,阿里,也都期待阿里巴巴的马云爸爸能够给我们免单,从而省去我们每天为钱烦恼的后顾之忧.虽然今天要吃的瓜是有关阿里的,但是并 ...

  7. Chrome浏览器切页快捷键

    Chrome浏览器切换标签页快捷键 1.Ctrl + Tab 向左切换标签页 2.Ctrl + shift + Tab 向右切换 3.Ctrl + 1 切换到第一个页面 4.Ctrl + 9 切换到最 ...

  8. android studio :Timeout waiting to lock daemon addresses registry

    一.开发中 android studio 突然遇到下面的错误提示: Error:Timeout waiting to lock daemon addresses registry. It is cur ...

  9. 15 个优秀开源的 Spring Boot 学习项目

    Spring Boot 算是目前 Java 领域最火的技术栈了,松哥年初出版的 <Spring Boot + Vue 全栈开发实战>迄今为止已经加印了 8 次,Spring Boot 的受 ...

  10. java 协程

    协程是比线程更轻量级的程序处理单元,也可以说是运行在线程上的线程,由自己控制 1.适用于被阻塞的,且需要大量并发的场景. 2.不适用于,大量计算的多线程,遇到此种情况,更好实用线程去解决. 虽然Jav ...