【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 ...
随机推荐
- Uva 136 丑数
n^2暴力就完事,但是上限要高,不然就算不到对应的1500,刘汝佳的写法更好. #include <bits/stdc++.h> using namespace std; const in ...
- css 把图片变成灰色
3.14号刚下班,噩耗传来,伟大的物理学家斯蒂芬·威廉·霍金去世了. 同事正好叫我吃饭,几分钟内去看了一眼百度百科,一看也都变黑白了,可是查看图片还是彩色的,也是哪有这么快的时间来p图呢,回来搜了一下 ...
- Spring boot security权限管理集成cas单点登录
挣扎了两周,Spring security的cas终于搞出来了,废话不多说,开篇! Spring boot集成Spring security本篇是使用spring security集成cas,因此,先 ...
- HDU 2063 过山车(二分图 && 匈牙利 && 最小点覆盖)
嗯... 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2063 这是一道很经典的匈牙利问题: 把男同学看成左边点,女同学看成右边点,如果两个同学愿意同 ...
- 将训练好的Tensorflow模型部署到web应用中
做一个简易web使用Flask是最好的选择,不仅上手快,使用也很便利.Django很强大也很好用,但一次就会创建一个项目的所需的文件,我觉得对于测试一个模型在web端有没有效果没必要用它. flask ...
- 模板元编程(Template metaprogramming)
https://en.wikipedia.org/wiki/Template_metaprogramming 没看懂...只知道了模板元编程的代码是在编译期运行的... 敲了2个例子: 1. #inc ...
- python练习:斐波那契数列的递归实现
python练习:斐波那契数列的递归实现 重难点:递归的是实现 def fib(n): if n==0 or n==1: return 1 else: return fib(n-1)+fib(n-2) ...
- 计算机二级-C语言-程序填空题-190117记录-对文件的处理,复制两个文件,往新文件中写入数据。
//给定程序的功能是,调用函数fun将指定源文件中的内容赋值到指定目标文件中,复制成功时函数返回1,失败时返回0,把复制的内容输出到终端屏幕.主函数中源文件名放在变量sfname中,目标文件名放在变量 ...
- arc066E - Addition and Subtraction Hard
题目链接 题目大意 给定一个只含加减和数字的表达式,在其中添加括号,使其值最大. 解题思路 显然,只有减号后面的括号会使其中表达式的值取反. 然后只有已经有左括号时才能加入右括号. 所以用\(f_0\ ...
- npm 配置国内淘宝镜像
淘宝NPM镜像官网:http://npm.taobao.org/ npm config set registry=http://registry.npm.taobao.org -g 安装cnpm: n ...