1022 Digital Library (30 分)

本文介绍了一种基于图书信息的检索系统设计,该系统能够处理大量书籍数据,包括书名、作者、关键词、出版社及出版年份,并能根据读者查询快速返回相关书籍列表。系统采用书籍结构体存储信息,通过排序和搜索算法实现高效查询。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目链接:

https://pintia.cn/problem-sets/994805342720868352/problems/994805480801550336

题目:

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 (≤10​4​​) 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

解题思路:

第一种思路:模拟

1、创建一个书籍结构体,用来保存书中的所有关键信息。

2、将书籍按照id排序(注意可能出现71的情况,我们要使用 %07d进行0的添加)。

3、使用自己编写的getWords处理括号(或者使用c++ stl getline 进行的读取)。

4、根据用户查询信息,进行分类匹配结果,输出结果即可。

第二种思路:map映射查询,将主题、内容等信息分别放到一个map<string,set<int>>中,用以进行查询。

解题代码:

#include <iostream>
#include<bits/stdc++.h>
using namespace std;
const int MAXSIZE = 10001;
const int wordsize = 1000;
struct Book{
    int id;
    char *ti;
    char *author;
    char *keyWords;
    char *publisher;
    char *year;
    friend bool operator < (Book b1,Book b2){
        return b1.id<b2.id;
    }
};
Book *bs;
int n,m;
char *getWord(){
    char *a = new char[1000];
    char ch;
    int sum = 0;
    while((ch=getchar())!=NULL){
        if(ch=='\n') break;
        //if(ch!=' '&&ch!=':'){
            a[sum++] = ch;
       // }
    }
    a[sum] = '\0';
    return a;
}
//bool cmp()
void init(){
    cin>>n;
    bs = new Book[n];
    for(int i = 0 ;i<n;i++){
        cin>>bs[i].id;
        getchar();
        bs[i].ti = getWord();
       // getchar();
        bs[i].author = getWord();
        //cout<<bs[i].author<<endl;
        bs[i].keyWords = getWord();
        bs[i].publisher = getWord();
        bs[i].year = getWord();
    }
    sort(bs,bs+n);
}
struct Query{
    int num;
    char *content;
    queue<int> bookId;
};
/**

    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

*/
//找子串
bool getSub(char *p,char *s){
    int len = strlen(p);
    char word[100] ;
    int st = 0;
    for(int i = 0 ;i<len;i++){
        if(p[i]!=' '){
            char ch  = p[i];
            //if(ch>='A'&&ch<='Z') ch = ch-'A'+'a';
            word[st++] = p[i];
        }else{
            word[st] = '\0';
            if(strcmp(word,s)==0){
                return true;
            }
            st = 0;
        }
    }
    if(st!=0){
         word[st] = '\0';
         if(strcmp(word,s)==0){
                return true;
            }
    }
    return false;
}
queue<int> getBooK(int i,char *content){
    queue<int> q ;
    switch(i){
    case 1:
        for(int i =0;i<n;i++){
            if(strcmp(bs[i].ti,content)==0){
                q.push(bs[i].id);
            }
        }
        break;
    case 2:
        for(int i =0;i<n;i++){
            if(strcmp(bs[i].author,content)==0){
                q.push(bs[i].id);
            }
        }
        break;
    case 3:
        for(int i =0;i<n;i++){
            if(getSub(bs[i].keyWords,content)){
                q.push(bs[i].id);
            }
        }
        break;
    case 4:
        for(int i =0;i<n;i++){
            if(strcmp(bs[i].publisher,content)==0){
                q.push(bs[i].id);
            }
        }
        break;
    case 5:
        for(int i =0;i<n;i++){
            if(strcmp(bs[i].year,content)==0){
                q.push(bs[i].id);
            }
        }
        break;
    }
    return q;
}

void query(){
    int m;
    cin>>m;
    Query *qs = new Query[m];
    for(int i = 0 ; i <m;i++){
        char s[5];
        cin>>s;
        qs[i].num = s[0] - '0'+0;
        getchar();
        qs[i].content = getWord();
        //进行查询

    }
    for(int i = 0 ;i<m;i++){
        qs[i].bookId = getBooK(qs[i].num,qs[i].content);
    }
    //输出
    queue<Query> nq;
    for(int i = 0 ;i<m;i++){
        if(!qs[i].bookId.empty()){
            printf("%07d",qs[i].num);
            cout<<": "<<qs[i].content<<endl;
            while(!qs[i].bookId.empty()){
                int j = qs[i].bookId.front();
                cout<<j<<endl;
                qs[i].bookId.pop();
            }
        }else{
             printf("%07d",qs[i].num);
             cout<<": "<<qs[i].content<<endl;
             cout<<"Not Found"<<endl;
        }
    }
}
int main()
{
    init();
    query();
    //cout<<getWord();
}

 

资源下载链接为: https://pan.quark.cn/s/f989b9092fc5 在 Android 应用开发中,开发一款仿 OPPO 手机计算器的应用是极具实践价值的任务,它融合了 UI 设计、事件处理以及数学逻辑等多方面的技术要点。当前的“最新版仿 OPPO 手机计算器--android.rar”压缩包中,提供了该计算器应用的源代码,这为开发者深入学习 Android 编程提供了宝贵的资源。 UI 设计是构建此类计算器应用的基石。OPPO 手机的计算器界面以清晰的布局和良好的用户交互体验著称,其中包括数字键、运算符键以及用于显示结果的区域等关键元素。开发者需借助 Android Studio 中的 XML 布局文件来定义这些界面元素,可选用 LinearLayout、GridLayout 或 ConstraintLayout 等布局管理器,并搭配 Button 控件来实现各个按键功能。同时,还需考虑不同辨率屏幕和设备尺寸的适配问题,这通常涉及 Density Independent Pixel(dp)单位的应用以及 Android 尺寸资源的合理配置。 事件处理构成了计算器的核心功能。开发者要在每个按钮的点击事件中编写相应的处理代码,通常通过实现 OnClickListener 接口来完成。例如,当用户点击数字键时,相应的值会被添加到显示区域;点击运算符键时,则会保存当前操作数并设定运算类型。而对于等号(=)按钮,需要执行计算操作,这往往需要借助栈数据结构来存储操作数和运算符,并运用算法解析表达式以完成计算。 数学逻辑的实现则是计算器功能的关键体现。在 Android 应用中,开发者可以利用 Java 内置的 Math 类,或者自行设计算法来完成计算任务。基本的加减乘除运算可通过简单的算术操作实现,而像求幂、开方等复杂运算则需调用 Math 类的相关方法。此外
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值