`
249326109
  • 浏览: 56056 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

1022. Digital Library (30)

 
阅读更多

链接:http://pat.zju.edu.cn/contests/pat-a-practise/1022

 

题意:给定 N (<=10000) 本书的信息,包括 7 位 ID,最多 80 字符的书名,最多 80 字符的作者名, 多个最多 10 字符的关键词,最多 80 字符的出版商和属于 [1000, 3000]的出版时间。 另给出 M (<=1000) 的查询请求,按照查询格式分为:

1: 书名

2: 作者

3: 关键词

4: 出版商

5: 年份

 

分析:其他属性排序后遍历查询即可,关键词合理的方法应该建立倒排索引,这里用vector水过了。。

 

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<vector>
#include<string>

using namespace std;

typedef struct Book {
	int id;
	char title[85];
	char author[85];
	vector<string> keywords;
	char publisher[85];
	char year[10];

} Book;

Book book[10005];

int cmp(const void*a, const void*b) {
	Book* aa = (Book*) a;
	Book* bb = (Book*) b;
	return aa->id - bb->id;

}

int main() {
//	freopen("in.txt", "r", stdin);
	int n;
	scanf("%d", &n);
	int i;
	char keyword[15];
	for (i = 0; i < n; i++) {
		scanf("%d", &book[i].id);
		getchar();
		gets(book[i].title);
		gets(book[i].author);

		char ch;
		while (scanf("%s", keyword)) {
			string s = keyword;
			book[i].keywords.push_back(s);
			ch = getchar();
			if (ch == '\n')
				break;
		}

		gets(book[i].publisher);
		scanf("%s", book[i].year);

	}
	qsort(book, n, sizeof(Book), cmp);

	int m;
	scanf("%d", &m);
	getchar();
	char query[100];
	while (m--) {
		int found = 0;
		gets(query);
		printf("%s\n", query);
		if (query[0] == '1') {
			for (i = 0; i < n; i++) {
				if (strcmp(book[i].title, &query[3]) == 0) {
					printf("%07d\n", book[i].id);
					found = 1;
				}
			}
		} else if (query[0] == '2') {
			for (i = 0; i < n; i++) {
				if (strcmp(book[i].author, &query[3]) == 0) {
					printf("%07d\n", book[i].id);
					found = 1;
				}
			}
		} else if (query[0] == '3') {
			int j;
			for (i = 0; i < n; i++) {
				for (j = 0; j < book[i].keywords.size(); j++)
					if (strcmp(book[i].keywords[j].c_str(), &query[3]) == 0) {
						printf("%07d\n", book[i].id);
						found = 1;
					}
			}

		} else if (query[0] == '4') {
			for (i = 0; i < n; i++) {
				if (strcmp(book[i].publisher, &query[3]) == 0) {
					printf("%07d\n", book[i].id);
					found = 1;
				}
			}
		} else {
			for (i = 0; i < n; i++) {
				if (strcmp(book[i].year, &query[3]) == 0) {
					printf("%07d\n", book[i].id);
					found = 1;
				}
			}

		}
		if(!found)
			printf("Not Found\n");

	}

	return 0;
}

 

 

分享到:
评论

相关推荐

    1.Digital Electronics and VHDL Design with LabVIEW FPGA.zip

    4. **数字逻辑VI库**:"Digital_Logic_VI_Library.zip"则可能是一个包含预定义LabVIEW函数和虚拟仪器的库,专用于数字逻辑分析和设计。这个库可以帮助用户快速构建和测试数字逻辑设计,提供了各种逻辑门、触发器、...

    Data Structures and Algorithms in C++, 2nd

    Data Structures and Algorithms in C++, 2nd Data Structures and Algorithms in C++, 2nd Data Structures and Algorithms in C++, 2nd

    sony digital library

    sony digital library

    THE ACM DIGITAL LIBRARY (DL) 用户指南

    THE ACM DIGITAL LIBRARY (DL) 用户指南

    DSP28335 Digital Control Library使用说明

    ### DSP28335 Digital Control Library使用说明 #### 一、引言 在现代工业自动化与控制领域中,DSP28335 Digital Control Library (简称DCL) 是一个非常重要的工具集,用于简化基于TI C2000系列微控制器(DSP28335)的...

    TPAC Digital Library Portal-开源

    TPAC Digital Library Portal 是一个专为发布大型科学数据目录而设计的开源Web应用程序。这个平台致力于提供高效、灵活且易于管理的方式来存储、检索和分享大量的科研数据。作为一个开源项目,它的源代码可供公众...

    C++ Library for Audio Digital Signal Processing.zip

    本文将深入探讨“C++ Library for Audio Digital Signal Processing”这一主题,帮助开发者理解其核心概念、主要功能以及实际应用。 音频数字信号处理库通常包含一系列函数和类,用于执行音频数据的采集、分析、...

    Tricks of the Windows video Game Programming---part1

    Tricks of the Windows video Game Programming &lt;br&gt;PART I Windows Programming Foundations 7 1 Journey into the Abyss 9 A Little History.............................................................

    verilog_cordic_core_latest.tar.gz_library verilog_verilog librar

    这个"verilog_cordic_core_latest.tar.gz"是一个压缩包,包含了Verilog实现的CORDIC(Coordinate Rotation Digital Computer)核心库。CORDIC算法是一种在硬件中高效解决三角函数和向量旋转问题的算法,特别适用于...

    Digital Systems Engineering 数字系统工程 part1

    and this book is one of the best available....Overall, this book will be a valuable addition to the library of every engineer involved in the design of digital systems, and for those who have only ...

    Crypto Samples (C# for .NET 2.0) 加密范例.

    This library exposes security functionality to the programmer, such as random number generation, hashing, salted hashing, message authentication code, symmetric encryption, asymmetric encryption, ...

    C.Advanced.module.digital.encryption.code.rar_加密解密_Visual_C++_

    综上所述,"C Programming Advanced design module digital encryption code"涵盖的是利用C++进行高级数字加密设计的实践和理论知识,结合Visual C++的开发环境,有助于开发者构建自己的加密解密解决方案,保障信息...

    Digital.zip

    【标签】"MFC"是Microsoft Foundation Class Library的缩写,这是一个由微软开发的C++类库,用于构建Windows应用程序。MFC提供了对Windows API的封装,使得开发者能够更方便地使用操作系统的服务。它包括了窗口、...

    Digital Libraries by William Arms

    英文版 This is a fascinating period in the history of libraries and publishing. For the first time, it is possible to build large-scale ... In a completely digital library, nothing need ever reach paper.

    Android代码-Rx2Animations

    compile 'oxim.digital:rx2anim:0.9.1' compile 'io.reactivex.rxjava2:rxandroid:2.0.1' compile 'io.reactivex.rxjava2:rxjava:2.0.6' RxJava version compatibility: This Rx2Animations library is only ...

    世界某地区的图书馆的建筑学报.pdf

    The spacious atrium, stretching from east to west, serves as a unifying element and provides a sense of orientation for visitors navigating the vast library. Moreover, the atrium's design fosters a ...

    Effective C++ Digital Collection 140 Ways to Improve Your Programming (2018).rar

    《Effective C++ Digital Collection 140 Ways to Improve Your Programming》是C++编程领域的一本经典著作,由著名C++专家Scott Meyers撰写。这本书集合了他对C++编程的深刻理解和实践经验,旨在帮助读者提升代码...

    Semantic Personal Digital Library-开源

    SPDL,全称为Semantic Personal Digital Library,是一个基于Java语言开发的开源软件,旨在帮助用户高效地管理和检索个人的PDF文档库。这个项目的核心理念是利用语义技术来增强文档的组织和搜索能力,使用户能够以...

    A C# DICOM Library.zip

    这个"A C# DICOM Library.zip"文件很可能包含了源代码、文档和其他资源,帮助开发者集成DICOM功能到他们的应用程序中。 首先,让我们深入了解一下DICOM标准的核心概念。DICOM标准定义了数据结构、通信协议和文件...

Global site tag (gtag.js) - Google Analytics