PAT A1022 Digital Library

1022 Digital Library

分数 30

作者 CHEN, Yue

单位 浙江大学

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 (≤104) 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

  

* 由于题目的输出由查询编号决定,那么就可以将每个查询编号对应的信息用一个map容器
 * 存储,map的第一个值的类型为string,存储每个序号对应的信息(书名,作者,...)的
 * 字符串,但是输入的关键词要将其拆分成单词存储,因为查询的关键词是以单词进行查询的;
 * map的第二个值得类型为set<string>,存储每个信息所对应的书的编号,由于set是自动升序
 * 排序的,这也正符合题目的要求;
 *

 * 最后要注意查询时的输入,我开始用的是两个string来进行输入,即:
 *  string op, t;
 *  cin >> op;
 *  getline(cin, t);
 *  但要注意此时的t是连中间的那个空格也一起读入的,中间用getchar()来吸收掉那个空格应该是
 *  可以的;
 *
 *  其实完全可以直接这样写,更加便捷
 *  getline(cin, op);
    t = op.substr(3);
    
    map就是一个二维数组,当然可以这么写了:
    for(auto &a : mp[d][t]) mp是定义的一个数组,相当于此时的mp是三维数组
        cout << a << endl;

/**
 * 由于题目的输出由查询编号决定,那么就可以将每个查询编号对应的信息用一个map容器
 * 存储,map的第一个值的类型为string,存储每个序号对应的信息(书名,作者,...)的
 * 字符串,但是输入的关键词要将其拆分成单词存储,因为查询的关键词是以单词进行查询的;
 * map的第二个值得类型为set<string>,存储每个信息所对应的书的编号,由于set是自动升序
 * 排序的,这也正符合题目的要求;
 * 
 * 最后要注意查询时的输入,我开始用的是两个string来进行输入,即:
 *  string op, t;
 *  cin >> op;
 *  getline(cin, t);
 *  但要注意此时的t是连中间的那个空格也一起读入的,中间用getchar()来吸收掉那个空格应该是
 *  可以的;
 * 
 *  其实完全可以直接这样写,更加便捷
 *  getline(cin, op);
    t = op.substr(3);
    
    map就是一个二维数组,当然可以这么写了:
    for(auto &a : mp[d][t]) mp是定义的一个数组,相当于此时的mp是三维数组
        cout << a << endl;
*/

#include <iostream>
#include <map>
#include <set>
#include <string>

using namespace std;

map<string, set<string> > mp[6];

void Read()
{
    int n;
    cin >> n;
    getchar();  //吸收掉换行符必不可少
    string s[7];
    
    for(int i=0; i<n; ++i)
    {
        for(int j=0; j<6; ++j)
        {
            getline(cin, s[j]);
            if(j > 0 && j != 3) //第四个字符串需要特别处理一下,将其分解成单词
                mp[j][s[j]].insert(s[0]);
        }
        
        //第四个字符串需要特别处理一下,将其分解成单词
        int idx = 0;
        while(idx < s[3].size())
        {
            int len = 0, sta = idx;
            while(idx < s[3].size() && s[3][idx] != ' ')
                ++len , ++idx;
            string t = s[3].substr(sta, len);
            mp[3][t].insert(s[0]);
            ++idx;
        }
    }
    
    int m;
    cin >> m;
    getchar(); //吸收掉换行符
    
    string op, t;
    while (m -- )
    {
        getline(cin, op);
        t = op.substr(3);
        cout << op << endl;
        int d = op[0] - '0';
        /**
        scanf("%s ",op); //要这么写就需要将op改为字符数组
        getline(cin, t);
        int d = op[0] - '0';
        cout << op << ' ' << t << endl;
        */
        
        if(mp[d].find(t) == mp[d].end())
            puts("Not Found");
        else
        {
            for(auto &a : mp[d][t])
                cout << a << endl;
        }
            
    }
}

int main()
{
    Read();
    
    return 0;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/17117.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

Java基础(二十一):集合源码

Java基础系列文章 Java基础(一)&#xff1a;语言概述 Java基础(二)&#xff1a;原码、反码、补码及进制之间的运算 Java基础(三)&#xff1a;数据类型与进制 Java基础(四)&#xff1a;逻辑运算符和位运算符 Java基础(五)&#xff1a;流程控制语句 Java基础(六)&#xff1…

第十九章 观察者模式

文章目录 前言普通方式解决问题CurrentConditions 显示当前天气情况WeatherData 管理第三方Clint 测试 一、观察者模式(Observer)原理完整代码SubjectObserverWeatherData implements SubjectCurrentConditions implements ObserverBaiduSite implements ObserverClint 前言 普…

python人工智能【隔空手势控制鼠标】“解放双手“

大家好&#xff0c;我是csdn的博主&#xff1a;lqj_本人 这是我的个人博客主页&#xff1a; lqj_本人的博客_CSDN博客-微信小程序,前端,python领域博主lqj_本人擅长微信小程序,前端,python,等方面的知识https://blog.csdn.net/lbcyllqj?spm1011.2415.3001.5343哔哩哔哩欢迎关注…

SSL证书支持IP改成https地址

我们都知道SSL证书能为域名加密&#xff0c;那么IP地址可以实现https加密吗&#xff1f;答案当然是肯定的。为IP地址进行https加密不仅能保护IP服务器与客户端之间数据传输安全&#xff0c;还能对IP服务器进行身份验证&#xff0c;确保用户信息安全&#xff0c;增强用户对IP地址…

编译一个魔兽世界开源服务端Windows需要安装什么环境

编译一个魔兽世界开源服务端Windows需要安装什么环境 大家好我是艾西&#xff0c;去年十月份左右wy和bx发布了在停服的公告。当时不少小伙伴都在担心如果停服了怎么办&#xff0c;魔兽这游戏伴随着我们渡过了太多的时光。但已经发生的事情我们只能顺其自然的等待GF的消息就好了…

平均情况时间复杂度

// n表示数组array的长度 int find(int[] array, int n, int x) {int i 0;int pos -1;for (; i < n; i) {if (array[i] x){ pos i; break;}}return pos; } 通过以上代码&#xff0c;我们分析一下平均情况时间复杂度。 以上代码要查找的变量 x 在数组中的位置&#xff…

2023哪款蓝牙耳机性价比高?200左右高性价比蓝牙耳机推荐

现如今的蓝牙耳机越来越多&#xff0c;人们在选择时不免纠结&#xff0c;不知道选什么蓝牙耳机比较好&#xff1f;针对这个问题&#xff0c;我来给大家推荐几款性价比高的蓝牙耳机&#xff0c;一起来看看吧。 一、南卡小音舱Lite2蓝牙耳机 参考价&#xff1a;299 蓝牙版本&am…

【文件描述符|重定向|缓冲区】

1 C语言文件操作的回顾 这块博主在讲解C语言时就已经做了很详细的讲解&#xff0c;这里就不详细讲了&#xff0c;直接给出代码。 写操作&#xff1a; #include<stdio.h> #include<stdlib.h> #include<errno.h> #define LOG "log.txt" …

3DES实验 思考与练习:

T1&#xff1a;关于3DES的分析 和 库函数的思考——完全领悟了&#xff01;&#xff01;&#xff01; #include <stdio.h> #include <stdlib.h> #include <string.h> #include <openssl/des.h> /***********************************************…

【pyTorch学习笔记④】PyTorch基础·中篇

文章目录 三、Numpy与Tensor3.Tensor的索引4.Tensor的广播机制5.逐元素操作6.归并操作7.比较操作8.矩阵操作9.PyTorch与Numpy的比较 相关推荐 三、Numpy与Tensor 3.Tensor的索引 &#xff08;1&#xff09;item&#xff1a;若Tensor为单元素&#xff0c;则返回标量&#xff0…

对偶问题和KKT条件

KKT条件 对于不等式约束优化问题 min ⁡ f ( x ) s . t . g ( x ) ≤ 0 \min\quad f(x)\\ {\rm s.t.}\quad g(x)\leq 0 minf(x)s.t.g(x)≤0 拉格朗日函数为 L ( x , λ ) f ( x ) λ g ( x ) L(x,\lambda)f(x)\lambda g(x) L(x,λ)f(x)λg(x) 。 KKT条件包括 拉格朗日函…

工厂方法模式

// 简单工厂模式 #include <iostream> #include <string>// 抽象产品类 class Product { public:virtual ~Product() {}virtual std::string getName() 0; };// 具体产品类A class ProductA : public Product { public:std::string getName() {return "Produ…

(抄送列表,年会抽奖)笔试强训

博主简介&#xff1a;想进大厂的打工人博主主页&#xff1a;xyk:所属专栏: JavaEE初阶 目录 文章目录 一、[编程题]抄送列表 二、[编程题]年会抽奖 一、[编程题]抄送列表 链接&#xff1a;抄送列表__牛客网 来源&#xff1a;牛客网 题目&#xff1a; NowCoder每天要处理许多邮…

ChatGPT实现服务器体验沙箱

服务器体验沙箱 IT 人员在学习一门新技术时&#xff0c;第一个入门门槛通常都是"如何在本地安装并成功运行"。因此&#xff0c;很多技术的官网都会通过沙箱技术&#xff0c;提供在线试用的 playground 或者按步模拟的 tour。让爱好者先在线尝试效果是否满足预期&…

MATLAB函数封装2:QT调用封装函数

在利用MATLAB进行封装函数之后&#xff0c;最主要的目的是对函数进行调用&#xff0c;能够对矩阵运算和其他算法的运行进行快捷处理。 在有了MATLAB函数之后封装成DLL文件之后&#xff0c;在QT中添加动态链接库&#xff0c;就可以实现函数的调用过程&#xff0c;这个过程相对简…

选择云原生是企业进行技术变革的必经之路

前言 众所周知&#xff0c;云计算领域的蓬勃发展&#xff0c;让越来越多的企业将自己的业务搬到云上&#xff0c;上云已经成为大部分企业的首选操作。无论是头部的中大型企业&#xff0c;还是普通的微小企业&#xff0c;企业业务是亘古不变的核心&#xff0c;这关系着企业的命脉…

7.0、Java继承与多态 - 多态的特性

7.0、Java继承与多态 - 多态的特性 面向对象的三大特征&#xff1a;封装性、继承性、多态性&#xff1b; extends继承 或者 implements实现&#xff0c;是多态性的前提&#xff1b; 用学生类创建一个对象 - 小明&#xff0c;他是一个 学生&#xff08;学生形态&#xff09;&…

彻底告别手动配置任务,魔改xxl-job!

分析 改造 1、接口调用 2、创建新注解 3、自动注册核心 4、自动装配 测试 测试后 XXL-Job是一款非常优秀的任务调度中间件&#xff0c;其轻量级、使用简单、支持分布式等优点&#xff0c;被广泛应用在我们的项目中&#xff0c;解决了不少定时任务的调度问题。不仅如此&a…

TIM-定时器——STM32

TIM-定时器——STM32 TIM(Timer)定时器 定时器可以对输入的时钟进行计数&#xff0c;并在计数值达到设定值时触发中断 16位计数器、预分频器、自动重装寄存器的时基单元&#xff0c;在72MHz计数时钟下可以实现最大59.65s的定时 不仅具备基本的定时中断功能&#xff0c;而且还包…

Mybatis方式完成CRUD操作

Mybatis方式完成CRUD操作 文章目录 Mybatis方式完成CRUD操作1、java以Mybatis方式操作DB1.1、配置数据源-创建 resources/mybatis-config.xml1.2、创建java bean-Monster1.3、配置Mapper接口声明方法1.4、配置xxMapper&#xff0c;完成SQL配置,实现CRUD操作1.5、Test测试 2、需…