题意:

输入一个正整数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. 分布式系统:CAP 理论的前世今生

    CAP 理论是分布式系统设计中的一个重要理论,虽然它为系统设计提供了非常有用的依据,但是也带来了很多误解.本文将从 CAP 诞生的背景说起,然后对理论进行解释,最后对 CAP 在当前背景下的一些新理解 ...

  2. 你了解真正的 restful API 吗?

    本文原创地址,博客:https://jsbintask.cn/2019/03/20/api/restful-api-best-practices/(食用效果最佳),转载请注明出处! 前言 在以前,一个 ...

  3. P1030 求先序排列 (一个非常棒的写法)

    理论正确就是真正的正确,误... 就是找嘛,找到每一个对应字符,然后对应的左右子树的区间,然后就可以了. #include <bits/stdc++.h> using namespace ...

  4. Flex布局如何实现最后一个元素右对齐(CSS)

    在最后一项元素使用样式: margin-left: auto;

  5. ubuntu安装与设置

    为学习Linux,在虚拟机中安装类ubuntu18.04,刚装完系统时间是不对的,系统中也没有gcc,g++. 关于安装软件无非就是: sudo apt-get install gcc sudo ap ...

  6. javac 编译引用外部指定jar包进行编译和执行编译后的class文件

    1.libs新建文件夹存放依赖所有jar包 2.cmd 执行: 2.1 javac -encoding UTF-8 -classpath .;C:\Users\chenquan\IdeaProject ...

  7. IIS 部署 web service

    1.在控制台检查 IIS 功能是否已经全部启用 2.重新注册IIS 3.设定程序池的正确版本

  8. python学习HTML之CSS(2)

    1.边框的属性设置 PS:边框的高度和宽度可以采用百分比,但是高度方向的百分比基本无用,因为基数没定,参考没意义!! 2.内边距和外边距 3.在右下角添加一个“回顶部”的标签. <div> ...

  9. iOS 与 js交互的其一方法 WebViewJavascriptBridge的使用

    #import <WebViewJavascriptBridge.h> /// @interface ZWBridgeViewController ()<WKNavigationDe ...

  10. twisted reactor calllater实现

    twisted reactor calllater实现 1.      calllater实现代码 测试源码: from twisted.internet import reactor from tw ...