链接: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; }
相关推荐
Data Structures and Algorithms in C++, 2nd Data Structures and Algorithms in C++, 2nd Data Structures and Algorithms in C++, 2nd
sony digital library
THE ACM DIGITAL LIBRARY (DL) 用户指南
DSP28335 Digital Control Library使用说明
C++ Library for Audio Digital Signal Processing
CANbus CANopen I/O Support Library for Analog, Digital, Serial, ASI-bridge fieldbus devices & Extension Layer DS402 for Motion Drive Support (Master) Ready to work with QNX / Neutrino® O.S Ready to ...
Tricks of the Windows video Game Programming <br>PART I Windows Programming Foundations 7 1 Journey into the Abyss 9 A Little History.............................................................
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 ...
This library exposes security functionality to the programmer, such as random number generation, hashing, salted hashing, message authentication code, symmetric encryption, asymmetric encryption, ...
英文版 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.
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 ...
Lessons learned from developing and evaluating a comprehensive digital library for engineering education
Altera FPGA_CPLD设计 基础篇
一种基于分配因子的链接分析算法,范鑫鑫,,随着整个万维网的迅速发展,很难为用户提供相关而准确的查询信息。Web结构挖掘在数据挖掘领域起着很重要的角色,PageRank和HITS是Web结
digital_library
Creates the Hspice library file by concatenating the netlists of digital cells from the characterization tree.
SchoolOS数字图书馆是免费的非商业DVD(2GB appx),其中包含98本书用于学校教育。 如果您知道一本好的电子书,请给我发送电子邮件-narendra AT narendrasisodiya.com访问-http://schooloslibrary.sf.net
The l3d Library Classes........................................8 Sample l3d Program ........................................8 l3d Directory Structure ....................................12 The Five-...
敏锐度经历了几乎完全的重写。 有关详细信息,请参见Github页面-https://github.com/AcumenProject [OLD描述] Acumen是... 易于设置和管理,不使工作流程复杂,支持所有浏览器,并自动创建和更新其自己的索引数据库。
SPDL代表语义个人数字图书馆,它是一个用于管理PDF文档的开源Java项目。 该项目允许用户表达有关文档的信息,以不同的方式对文档进行分类和检索。