PAT 1022. Digital Library (30)

pandas,构造MultiIndex的四种方法:from_tuples、from_arrays、from_product、from_frame 1、from_tuples:通过 “元组对” 构造MultiIndex """ 一对元组,为一个索引 """ tuples = [(1, 'red'), (1, 'blue'), (2, 'red'), (2, 'blue')] pd.MultiIndex.from_tuples(tuples, names=('number', 'color')) 2、from_arrays:通过 “列表元素的组合” 构造MultiIndex """ 列中表的元素,按位置 对应组合,形成索引 """ arrays 阅读详情

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

思路:题目有点长,主要要求是输入书本的相关信息,然后输入5种索引方式在这些书本信息中寻找匹配的结果。

 
#include<iostream>
#include<string>
#include<sstream>
#include<vector>
#include<algorithm>

using namespace std;

struct book { //书的信息
	string id;
	string name;
	string ath;
	vector<string> key;
	string pub;
	string time;
};   

int main()
{
	int n, m;
	string s, st;
	cin >> n;
	vector<book> b(n);
	for (int i=0; i!=n; ++i) { //输入书的信息
		cin >> b[i].id;
		cin.ignore();
		getline(cin, b[i].name);
		getline(cin, b[i].ath);
		getline(cin, s);
		istringstream is(s); //拆分字符串成为单独的关键字
		while (is >> s) 
			b[i].key.push_back(s);
		getline(cin, b[i].pub);
		cin >> b[i].time;
	}
	cin >> m;
	cin.ignore(); //在cin后用getline需要用,不然getline读入空行
	while(m--) {
		string s, st;
		vector<string> v;
		getline(cin, s);
		cout << s << endl;
		st.assign(s.begin()+3, s.end()); //索引内容
		for (int i=0; i!=n; ++i)  //按索引寻找书本匹配项
			if (st == b[i].name || st== b[i].ath || st==b[i].pub 
				|| st == b[i].time ||find(b[i].key.begin(), b[i].key.end(), st) != b[i].key.end() )
				v.push_back(b[i].id);

		sort (v.begin(), v.end()); //结果按id排序
		if (v.empty())
			cout << "Not Found" << endl;
		else
			for (int j=0; j!=v.size(); ++j)
				cout << v[j] << endl;
	}
	system("pause");
}


EMC设计技巧及经验总结3:TVS的使用 Way back in undergrad circuits class(回到本科时的电路课程), our TA(助教) loved to give uslittle “black box” circuits. We’d measure the voltage and current characteristics, then have to determine what compone 阅读详情

相关推荐

AI智能体赋能Cypress:自动化前端测试的新范式

自动化测试是现代软件工程保障质量的核心实践,其原理是通过脚本模拟用户操作,对软件功能进行验证。随着大语言模型(LLM)和智能体(Agent)技术的发展,测试自动化正迈向智能化新阶段。智能体能够理解自然语言描述的测试需求,并自主规划、执行测试步骤,这为应对前端UI频繁变更、测试用例维护成本高等挑战提供了新思路。在工程实践中,将Cypress这一流行的前端测试框架封装为智能体可调用的标准化技能(Skill),是实现这一愿景的关键。通过设计清晰的交互协议和状态管理机制,智能体可以像人类测试工程师一样“感知”页面状

weixin_33726318的博客 686

Digital Library

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 a

sheng_xc的专栏 627

ANSYS命令流黑箱揭秘:流体渗透压力载荷的七种收敛优化策略

本文深入解析ANSYS Workbench中流体渗透压力载荷的七种收敛优化策略,重点探讨接触探测点迭代逻辑、PPCN阈值动态调整及FPAT参数优化等关键技术。通过命令流示例和实战技巧,帮助工程师有效解决流体与结构相互作用仿真中的收敛难题,提升计算效率和精度。

weixin_29274337的博客 523

基于 CST 建模仿真的微波暗室性能评价方法

本文探讨了利用CST电磁仿真软件优化微波暗室设计的方法。针对传统暗室建设成本高、尺寸不可更改的问题,研究通过建立吸波材料模型(含碳聚氨酯角锥)和暗室结构模型(34m×32m×20m),采用CST的渐进求解器进行性能仿真。结果表明:在1-4GHz频段内反射系数低于-35dB,静区反射电平达-40dB,交叉极化隔离度优于25.8dB,场均匀性和多路径损耗均满足GJB6780-2009等标准要求。该方法实现了暗室建设前的性能预测,已成功应用于工程实践,有效降低了试错成本。

a18665053298的博客 545

EB TRESOS 29.0.0安装教程用于MCAL配置开发

本文介绍的搭建基于NXP官网提供EB软件,进行基于标准AUTOSAR软件底层驱动配置的开发

qq_53260940的博客 1879

DPO(Direct Preference Optimization)直接偏好优化

本文介绍了DPO(直接偏好优化)方法,该方法通过简化传统的RLHF(基于人类反馈的强化学习)流程,直接利用人类偏好数据进行模型优化。DPO的核心思想是跳过奖励模型训练和强化学习交互步骤,通过数学推导将优化目标转化为仅与策略概率分布相关的形式。推导表明最优策略与奖励模型之间存在显式关系,从而可以构建直接优化策略的损失函数。与RLHF相比,DPO简化了训练流程,提高了工程实现稳定性,同时保持了同等效果。

TeenLucifer的博客 1956

PAT甲级 -- 1022 Digital Library (30 分)

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 a...

猪の成长日记 239

医学图像处理入门:如何用Python将CT灰度图转换为伪彩色图像(附代码)

本文详细介绍了如何使用Python将CT灰度图转换为伪彩色图像,提升医学图像的可读性和诊断效率。通过OpenCV和Matplotlib等工具,实现灰度值到彩色空间的映射,特别适用于突出显示特定组织密度差异。文章包含完整代码示例和临床实用技巧,适合医学影像分析初学者和Python开发者。

gitlab7runner的博客 326

1022 Digital Library (30 分)

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 a...

chen_zan_yu_的博客 256

revit二次开发环境搭建(2024版)(小白友好)

revit二次开发环境配置,SDK、addin manager和lookup新手友好安装教程

m0_56961251的博客 1420

5、数据库基础概念与数据建模全解析

本文深入解析了数据库的基础概念,包括函数依赖、决定因素和多值依赖等关键依赖关系,同时探讨了数据建模的重要方法论,如IDEF1X、信息工程和陈方法。此外,还介绍了SQL Server管理工作室的图表功能,帮助用户进行数据库的可视化设计。通过本文,读者将掌握数据库设计的核心知识,为构建高效、可扩展的数据库系统奠定基础。

81

C++ vector的使用(一)

vector类似于数组。

的博客 1127

Gbase 8a GDCA考试真题100%

本文整理一些Gbase 8a中非常易错得考试真题及答案,而且都是不好搜的。加粗的是正确答案。

打工之路,一路生花 4306

PAT甲级 - 1022 Digital Library (30 分)

题目链接:PAT甲级 - 1022 Digital Library (30 分) A Digital Library contains millions of books, stored according to their titles, authors, key words of their abstracts, publishers, and published years. Each b...

284

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

1022 Digital Library (30 分)-PAT甲级

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 suppose

神笔码农.的博客 535

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

PAT 1022 Digital Library (30 分)

1022 Digital Library (30 分) 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 assigne...

peanWang的博客 226

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

PAT习题解:1022. Digital Library (30)

题目链接:http://www.patest.cn/contests/pat-a-practise/1022 这道题目我没想到什么好办法做,最后参考了闲云阁的文章,用map 和 set 做出来,算是顺便学习了一下 STL 里面 map 和 set 的用法。话说C++的输入输出真是麻烦啊,这题用Python做的话写起来会很简单吧。 #define _CRT_SECURE_NO_WARNING

by21010的专栏 760

PAT甲级 1022 Digital Library (30分)

1022 Digital Library (30分) 题目链接:PAT A 1022 题目大意:有一数字图书馆,对于每一本书给出如下信息:书的id,书的名字,书的作者,书的关键字,书的出版社以及书的出版年份。要求根据输入的查找信息输出相应书的ID(7位数字)。 思路分析:这道题题意很直观,但是需要用到的知识点比较多。首先根据题目要求可以分析出这道题一定是使用STL中的map去解决,而且由于题...

weixin_43684054的博客 217

PAT 1022 Digital Library (30)

首先是数据结构,gets的行输入以及scanf会接收末尾空格 strstr(str,substr)寻找str中是否有substr,没有返回null 最后sort一下,控制格式为%07d即可 #include #include #include #include #include using namespace std; const int N=10005; int cnt=0,n,

dimhat的专栏 789

[C++] PAT 1022 Digital Library (30分)

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 Tes.

快乐de约定的博客 2212

PAT A1022 Digital Library (30分)

题目链接: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 abst...

Rhao的博客 285

PAT A1022. Digital Library (30)

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 a

jolivan的博客 248

[PAT] 1022 Digital Library (30 分) Java

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 num...

Simma1101的博客 213

PAT 甲级 1022 Digital Library (30分)

原题链接:1022 Digital Library (30分) 题目大意: 一本书,只有一位作者,包含的关键词不超过 5 个。 总共不超过 1000 个不同的关键词,不超过 1000 个不同的出版商。 图书信息介绍完毕后,有一行包含一个整数 M,表示查询次数。 当读者查询某一关键信息时,你应该找到所有与查询相关的书籍,并将它们按 ID 的升序排序输出。 分析: 难点和重点在于:对字符串的读入和处理。 有格式的字符串用 scanf() 比较好 普通无空格字符串用cin 包含空格的字符串用 getline(),

EP的别三日 256

PAT 甲级 1022 Digital Library (30 分)

1022 Digital Library (30 分) 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 assign...

liuxinghui_SJTU的博客 245

PAT甲级1022 Digital Library (30 分)

1022Digital Library(30分) 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 assign...

Dexter 213
上一篇: PAT 1025. PAT Ranking (25)
下一篇: PAT 1028. List Sorting (25)
byhj
博客等级 码龄14年 1粉丝 83原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值