题意:

输入一个正整数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. confluence-工具安装

    wiki 企业级的应用知识库,个人感觉还是很不错的,所以自己本地也搭一个玩玩: 1.下载confluence wget https://downloads.atlassian.com/software ...

  2. AJAX技术初级探索

    一 概念 Ajax技术能够实现页面以异步方式从服务器获取信息,无需刷新页面 Ajax的核心技术是XMLHttpRequest对象(XHR) 异步实际就是请求数据的代码不会阻塞页面向下执行 二 原生Aj ...

  3. idea左侧出现日期和文件大小怎么关闭

    shift+alt+\

  4. 关于websockets的压测工具

    这是在workerman群中得到的信息,记录在此: loadrunner  jemeter

  5. 201771010135 杨蓉庆AND张燕 《面对对象程序设计(java)》第十一周学习总结

    1.实验目的与要求 (1) 掌握Vetor.Stack.Hashtable三个类的用途及常用API: (2) 了解java集合框架体系组成: (3) 掌握ArrayList.LinkList两个类的用 ...

  6. UIDocumentPickerViewController和UIDocumentInteractionController

    UIDocumentPickerViewController和UIDocumentInteractionController UIDocumentPickerViewController 补充一下,U ...

  7. jmeter csv 插件讲解

    1.变量名称 name,pwd 格式表示因为文本中分割默认是逗号所以变量设置也是按此格式如果想按其他格式可以在分隔符栏自定义 2.忽略首行: 有的csv读取你希望读取的数据有header如: user ...

  8. idea新建项目相关名词意义

    新建项目中的对比 建完之后的项目对比 对比 新建中Artifact的名称对应maven中名字 新建中package的名字对应的是项目中src下package名字 新建中project name的名字对 ...

  9. jvm 内存,线程,gc分析

    1.查看 gc的次数,和各个垃圾回收区域的内存比例  jstat : jstat -gcutil pid interval(ms) 例子:jstat -gcutil 332 1000 参数说明如下: ...

  10. python opencv:绘图 基本图形

    参数说明 • img:你想要绘制图形的那幅图像. • color:形状的颜色.以 RGB 为例,需要传入一个元组,例如:( 255,0,0)代表蓝色.对于灰度图只需要传入灰度值. • thicknes ...