A Digital Library contains millions of books, stored according to their titles, authors, key words of their abstracts, publishers, and published years. Each book is assigned an unique 7-digit number as its ID. Given any query from a reader, you are supposed
to output the resulting books, sorted in increasing order of their ID's.

Input Specification:

Each input file contains one test case. For each case, the first line contains a positive integer N (<=10000) which is the total number of books. Then N blocks follow, each contains the information of a book in 6 lines:

  • Line #1: the 7-digit ID number;
  • Line #2: the book title -- a string of no more than 80 characters;
  • Line #3: the author -- a string of no more than 80 characters;
  • Line #4: the key words -- each word is a string of no more than 10 characters without any white space, and the keywords are separated by exactly one space;
  • Line #5: the publisher -- a string of no more than 80 characters;
  • Line #6: the published year -- a 4-digit number which is in the range [1000, 3000].

It is assumed that each book belongs to one author only, and contains no more than 5 key words; there are no more than 1000 distinct key words in total; and there are no more than 1000 distinct publishers.

After the book information, there is a line containing a positive integer M (<=1000) which is the number of user's search queries. Then M lines follow, each in one of the formats shown below:

  • 1: a book title
  • 2: name of an author
  • 3: a key word
  • 4: name of a publisher
  • 5: a 4-digit number representing the year

Output Specification:

For each query, first print the original query in a line, then output the resulting book ID's in increasing order, each occupying a line. If no book is found, print "Not Found" instead.

Sample Input:

3
1111111
The Testing Book
Yue Chen
test code debug sort keywords
ZUCS Print
2011
3333333
Another Testing Book
Yue Chen
test code sort keywords
ZUCS Print2
2012
2222222
The Testing Book
CYLL
keywords debug book
ZUCS Print2
2011
6
1: The Testing Book
2: Yue Chen
3: keywords
4: ZUCS Print
5: 2011
3: blablabla

Sample Output:

1: The Testing Book
1111111
2222222
2: Yue Chen
1111111
3333333
3: keywords
1111111
2222222
3333333
4: ZUCS Print
1111111
5: 2011
1111111
2222222
3: blablabla
Not Found
思路:输入后,排序,不会超时.注释部分,year用int表示,有个case错误;换成了char数组,就正确了……奇怪!
/*
#include <iostream>
#include"stdio.h"
#include"stdlib.h"
#include"algorithm"
#include"string.h"
using namespace std; struct book{
char id[8];
char title[81];
char author[81];
char key[61];
char publisher[81];
int year;
};
bool sortById(struct book b1,struct book b2){
if(strcmp(b1.id,b2.id)<0)
return true;
return false;
}
int main()
{
int N,M;
scanf("%d",&N);
struct book b[10000]; for(int i=0;i<N;i++){
scanf("%s",b[i].id);
getchar();//读取末尾的换行符 gets(b[i].title); gets(b[i].author); gets(b[i].key); gets(b[i].publisher); scanf("%d",&b[i].year); }
sort(b,b+N,sortById);//按照书的ID递增排序 scanf("%d",&M);
char choice[3];
int year;
for(int i=0;i<M;i++){
scanf("%s",choice);
getchar();//读取空格
char str[81]; bool flag = false; if(strcmp(choice,"1:")==0){
gets(str);
printf("%s %s\n",choice,str);
for(int j=0;j<N;j++){
if(strcmp(b[j].title,str)==0){
printf("%s\n",b[j].id);
flag =true;
}
}
}
else if (strcmp(choice,"2:")==0){
gets(str);
printf("%s %s\n",choice,str); for(int j=0;j<N;j++){
if(strcmp(b[j].author,str)==0){
printf("%s\n",b[j].id);
flag =true;
}
}
}
else if (strcmp(choice,"3:")==0){
gets(str);
printf("%s %s\n",choice,str); for(int j=0;j<N;j++){
string s = b[j].key;
int pos = s.find(str);
int len = strlen(str);
if(pos!=s.npos&&(s[pos+len]==' '||s[pos+len]=='\0')&&(pos==0||s[pos-1]==' '))//避免str只是某个关键字的子串
{
printf("%s\n",b[j].id);
flag =true;
}
}
}
else if (strcmp(choice,"4:")==0){
gets(str);
printf("%s %s\n",choice,str); for(int j=0;j<N;j++){
if(strcmp(b[j].publisher,str)==0){
printf("%s\n",b[j].id);
flag =true;
}
}
}
else if (strcmp(choice,"5:")==0){
scanf("%d",&year);
printf("%s %d\n",choice,year); for(int j=0;j<N;j++){
if(b[j].year==year){
printf("%s\n",b[j].id);
flag =true;
}
}
}
if(false == flag){
printf("Not Found\n");
}
}
return 0;
}
*/
#include <iostream>
#include"stdio.h"
#include"stdlib.h"
#include"algorithm"
#include"string.h"
using namespace std; struct book{
char id[8];
char title[81];
char author[81];
char key[61];
char publisher[81];
char year[5];
};
bool sortById(struct book b1,struct book b2){
if(strcmp(b1.id,b2.id)<0)
return true;
return false;
}
int main()
{
int N,M;
scanf("%d",&N);
struct book b[10000]; for(int i=0;i<N;i++){
scanf("%s",b[i].id);
getchar();//读取末尾的换行符 gets(b[i].title); gets(b[i].author); gets(b[i].key); gets(b[i].publisher); gets(b[i].year); }
sort(b,b+N,sortById);//按照书的ID递增排序 scanf("%d",&M);
char choice[3];
for(int i=0;i<M;i++){
scanf("%s",choice);
getchar();//读取空格
char str[81]; bool flag = false;
gets(str);
if(strcmp(choice,"1:")==0){ printf("%s %s\n",choice,str);
for(int j=0;j<N;j++){
if(strcmp(b[j].title,str)==0){
printf("%s\n",b[j].id);
flag =true;
}
}
}
else if (strcmp(choice,"2:")==0){
printf("%s %s\n",choice,str); for(int j=0;j<N;j++){
if(strcmp(b[j].author,str)==0){
printf("%s\n",b[j].id);
flag =true;
}
}
}
else if (strcmp(choice,"3:")==0){
printf("%s %s\n",choice,str); for(int j=0;j<N;j++){
string s = b[j].key;
int pos = s.find(str);
int len = strlen(str);
if(pos!=s.npos&&(s[pos+len]==' '||s[pos+len]=='\0')&&(pos==0||s[pos-1]==' '))//避免str只是某个关键字的子串
{
printf("%s\n",b[j].id);
flag =true;
}
}
}
else if (strcmp(choice,"4:")==0){
printf("%s %s\n",choice,str); for(int j=0;j<N;j++){
if(strcmp(b[j].publisher,str)==0){
printf("%s\n",b[j].id);
flag =true;
}
}
}
else if (strcmp(choice,"5:")==0){
printf("%s %s\n",choice,str); for(int j=0;j<N;j++){
if(strcmp(b[j].year,str)==0){
printf("%s\n",b[j].id);
flag =true;
}
}
}
if(false == flag){
printf("Not Found\n");
}
}
return 0;
}

												

1022. Digital Library (30)的更多相关文章

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

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

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

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

  3. 1022 Digital Library (30 分)

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

  4. 1022. Digital Library (30) -map -字符串处理

    题目如下: A Digital Library contains millions of books, stored according to their titles, authors, key w ...

  5. 1022 Digital Library (30)(30 point(s))

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

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

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

  7. PAT Advanced 1022 Digital Library (30 分)

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

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

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

  9. PAT (Advanced Level) 1022. Digital Library (30)

    简单模拟题. 写的时候注意一些小优化,小心TLE. #include<iostream> #include<cstring> #include<cmath> #in ...

随机推荐

  1. 单链表带头结点&不带头结点

    转自:http://blog.csdn.net/xlf13872135090/article/details/8857632 Node *head;  //声明头结点   带头结点初始化 void I ...

  2. 利用Aspose.Word控件和Aspose.Cell控件,实现Word文档和Excel文档的模板化导出

    我们知道,一般都导出的Word文档或者Excel文档,基本上分为两类,一类是动态生成全部文档的内容方式,一种是基于固定模板化的内容输出,后者在很多场合用的比较多,这也是企业报表规范化的一个体现. 我的 ...

  3. 简单解释Windows如何使用FS段寄存器

    详见附件 jpg改rar

  4. 《大话》之 装饰模式 Vs 建造者模式

    一.简介: 装饰模式:     背景:小菜要见美女娇娇,感慨自己不会着装,怕给娇娇留下坏印象               内容:动态的给一个对象添加一些额外职责               图文并茂: ...

  5. Practical Java (一)关于reference

    Practice 1, 4, 7, 8 1. 参数传递:by value or by reference 变量型别:reference 和 primitive Java中的变量分为两种:referen ...

  6. 《DSP using MATLAB》示例Example4.15

    代码: b = [1/3, 1/3, 1/3]; a = [1, -0.95, 0.9025]; % x(n) y(n) coefficient [R, p, C] = residuez(b,a) M ...

  7. 【第三方登录】之QQ第三方登录

    最近公司做了个网站,需要用到第三方登录的东西.有QQ第三方登录,微信第三方登录.先把QQ第三方登录的代码列一下吧. public partial class QQBack : System.Web.U ...

  8. appium定位元素java篇【转】

    1.关于没有name,没有ID的元素的定位---通用篇解题思路:因为没有name,id:其实剩下的选择已不多,要么xpath,要么className.xpath木有好印象(稳定性不高,加之1.0x后需 ...

  9. 【bzoj4513】储能表【数位DP】

    本来是想去学数位DP,作死挑了这道题,爆炸... 听说正确姿势应该是去做bzoj4521[手机],听说迪克们当场都A了,Orz 然后对于4513,我只想说,一.脸.懵.逼 首先,我是无论如何都无法想到 ...

  10. 使用maven 如何生成源代码的jar包

    http://hw1287789687.iteye.com/blog/1943157