习题5-8 图书管理系统(Borrowers, UVa230)

习题5-8 图书管理系统(Borrowers, UVa230)
Before they are returned to the shelves, the returned
books are sorted by author and then title using the ASCII collating sequence.
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <utility>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cctype>
#define CLOSE() ios::sync_with_stdio(false)
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define IN() freopen("in.txt", "r", stdin)
#define OUT() freopen("out.txt", "w", stdout)
const int maxn = 1e5 + 5;
using LL = long long;
using UI = unsigned int;
using namespace std;
//------------------------------------------------------------------------------------------//
struct Book {
	string title, author;
	bool borrow, back, in_shelve = true;
	bool s;
	bool operator<(const Book &rhs) {
		if (author != rhs.author) return author < rhs.author;
		else return title < rhs.title;
	}
}book[maxn];
int cntb = 0;
map<string, int> rnk;
vector<string> t;

void Read_Books() {
	string in, s;
	while (getline(cin, in)) {
		if (in == "END") break;
		stringstream ss(in);
		int flag = 1;
		while (ss >> s) {
			if (s == "by") break;
			if (flag) {
				flag = 0; s = s.substr(1);
			}
			else s = " " + s;
			if (s.back() == '"') s.pop_back();
			book[cntb].title += s;
		}
		flag = 1;
		while (ss >> s) {
			if (flag) flag = 0;
			else s = " " + s;
			book[cntb].author += s;
		}
		//cout << book[cntb].author << endl << book[cntb].title << endl;
		cntb++;
	}
}

bool Read_Records() {
	string s;
	int flag = 1;
	while (cin >> s) {
		//cout << s << endl;
		if (s == "SHELVE") return true;
		else if (s == "END") return false;
		if (s == "BORROW") {
			flag = 1;
			string t;
			while (cin >> s) {
				if (flag) {
					flag = 0;
					s = s.substr(1);
				}
				else s = " " + s;
				if (s.back() == '"') {
					s.pop_back();
					t += s;
					break;
				}
				t += s;
			}
			book[rnk[t]].borrow = true;
			book[rnk[t]].in_shelve = false;
			//cout << t << endl;
		}
		if (s == "RETURN") {
			flag = 1;
			string t;
			while (cin >> s) {
				if (flag) {
					flag = 0;
					s = s.substr(1);
				}
				else s = " " + s;
				if (s.back() == '"') {
					s.pop_back();
					t += s;
					break;
				}
				t += s;
			}
			book[rnk[t]].back = true;
		}
	}
}

void Solve() {
	t.clear();
	bool have_book = false;
	//cout << "books : " << endl;
	for (int i = 0; i < cntb; i++) {
		if (book[i].in_shelve || book[i].back) {
			t.push_back(book[i].title);
			//cout << book[i].title << endl;
		}
		if (book[i].in_shelve) have_book = true;
	}
	if (!t.empty() && book[rnk[t[0]]].back && (t[0] == book[0].title || !have_book)) {
		cout << "Put " << "\"" << t[0] << "\"" << " first\n";
	}
	for (int i = 1; i < t.size(); i++) {
		if (book[rnk[t[i]]].back) cout << "Put " << "\"" << t[i] << "\"" << " after " << "\"" << t[i - 1] << "\"\n";
	}
	for (int i = 0; i < t.size(); i++) {
		if (book[rnk[t[i]]].back) {
			book[rnk[t[i]]].back = false;
			book[rnk[t[i]]].borrow = false;
			book[rnk[t[i]]].in_shelve = true;
		}
	}
	cout << "END\n";
}

int main() {
	//IN(); OUT();
	Read_Books();
	sort(book, book + cntb);
	for (int i = 0; i < cntb; i++) rnk[book[i].title] = i;
	while (Read_Records()) Solve();
	return 0;
}



//看了大佬的代码的改进版,无论是清晰度还是代码长度都好太多了
struct Book {
	string title, author;
	int status = 1;
};
vector<string> bvec;
map<string, Book> bmap;
bool cmp(const string &a, const string &b) {
	if (bmap[a].author != bmap[b].author) return bmap[a].author < bmap[b].author;
	else return bmap[a].title < bmap[b].title;
}

int main() {
	string s;
	Book b;
	//IN(); OUT();
	//cout << "Books :" << endl;
	while (getline(cin, s) && s != "END") {
		int p = s.find('"', 1);
		b.title = s.substr(0, p + 1);
		b.author = s.substr(p + 5);
		bvec.push_back(b.title);
		bmap[b.title] = b;
	}
	sort(bvec.begin(), bvec.end(), cmp);
	//for (int i = 0; i < bvec.size(); i++) cout << bvec[i] << endl;
	while (cin >> s && s != "END") {
		if (s == "SHELVE") {
			for (int i = 0; i < bvec.size(); i++)
				if (bmap[bvec[i]].status == -1) {
					int j;
					for (j = i; j >= 0; j--)
						if (bmap[bvec[j]].status == 1) break;
					if(j > -1) cout << "Put " << bvec[i] << " after " << bvec[j] << endl;
					else cout << "Put " << bvec[i] << " first" << endl;
					bmap[bvec[i]].status = 1;
				}
			cout << "END\n";
		}
		if (s == "BORROW") {
			getchar();
			getline(cin, s);
			//cout << "bo" << " : " << s << endl;
			bmap[s].status = 0;
		}
		if (s == "RETURN") {
			getchar();
			getline(cin, s);
			//cout << "re" << " : " << s << endl;
			bmap[s].status = -1;
		}
	}
	return 0;
}
/*
期末考试结束前,暂时先停一下。做这题时感觉胃疼。。。好难受,,明明很水的题却做了有大半天。
感觉我想题的过程还是不够完善,应该在敲题之前再好好想一想如何实现比较好再动手。
中间出现了一些问题啊,比如自定义结构体不能用vector,sort传char * 出现问题等。感觉应该是因为
自己定义的结构体不够完善,缺少很多操作的定义吧,还是用库函数的类型比较好。
刚开始还选错了方法,直接开字符串数组写,麻烦多,问题也多,像这类不知道具体个数的题,直接用vector就好了。
*/

系统介绍 图书馆管理系统主要的目的是实现图书馆信息管理图书馆的主要业务就是新书的借阅和归还,因此系统最核心的功能便是实现图书的借阅和归还。此外,还需要提供图书信息查询、读者图书借阅情况的查询等功能。项目实施后,能够提高图书馆图书借阅、归还流程,提高工作效率。整个项目需要在两个月的时间内交付用户使用。 操作注意事项 (1)本系统的用户名为:tsoft,密码为:111 (2)读者类型不同,可借图书的本数也有所区别。 操作流程 (1)用户登录图书馆管理系统后,可看到图书借阅排行榜,通过排行榜可以看出借阅图书的名称、图书类型、借阅次数等相关信息。 (2)单击“系统设置”/“图书馆信息”命令,对图书馆信息进行设置操作。 (3)单击“系统设置”/“管理员设置”命令,对管理信息进行添加、权限设置、查询及删除操作。 (4)单击“系统设置”/“参数设置”命令,对办证费用及有效期限信息进行添加操作。 (5)单击“系统设置”/“书架设置”命令,对书架信息进行添加、修改及删除操作。 (6)单击“读者管理”/“读者类型管理”命令,对读者类型信息进行添加、修改及删除操作。 (7)单击“读者管理”/“读者档案管理”命令,对读者信息进行添加、修改及删除操作。 (8)单击“图书管理”/“图书类型设置”命令,对图书类型信息进行添加、修改及删除操作。 (9)单击“图书管理”/“图书档案管理”命令,对图书信息进行添加、修改及删除操作。 (10)单击“图书借还”/“图书借阅”命令,对图书借阅信息添加操作。 (11)单击“图书借还”/“图书续借”命令,对图书续借信息进行添加操作。 (12)单击“图书借还”/“图书归还”命令,对图书归还信息进行添加操作。 (13)单击“系统查询”/“图书档案查询”命令,对图书档案信息进行查询操作。 (14)单击“系统查询”/“图书借阅查询”命令,对借阅的图书信息进行查询操作。 (15)单击“系统查询”/“借阅到期提醒”命令,对借阅到期提醒信息进行查询操作。 (16)单击“更改口令”按钮,对当前的用户密码进行修改操作。 (17)单击“退出系统”按钮,退出当前操作系统。
很抱歉,作为一名语言模型,我无法进行图形绘制。但是我可以为您提供一些关于图书管理系统类图绘制的指导。 在绘制图书管理系统的类图时,您需要考虑系统中的主要对象和它们之间的关系。一般来说,一个图书管理系统中的主要对象包括书籍、读者、图书管理员、借阅记录等。这些对象之间的关系可能包括继承、关联、聚合和组合等。 以下是一个简单的图书管理系统类图示例,希望能对您有所帮助: ``` +---------------------+ +---------------------+ | Book | | Reader | +---------------------+ +---------------------+ | - title : string | | - name : string | | - author : string | | - id : string | | - ISBN : string | | | | - publication_date:| | | | string | | | +---------------------+ +---------------------+ | | | | | | +---------------------+ +---------------------+ | BorrowRecord | | Library | +---------------------+ +---------------------+ | - book : Book | | - books : Book[] | | - reader : Reader | | - borrowers : | | - borrow_date : | | BorrowRecord[] | | string | +---------------------+ | - return_date : | | string | +---------------------+ ``` 在这个示例中,Book、Reader、BorrowRecord和Library都是类,每个类都有一些属性和方法。例如,Book类有标题、作者、ISBN和出版日期等属性,而Reader类有姓名和ID等属性。BorrowRecord类则包含了借阅日期和归还日期等属性,同时包含了一个Book对象和一个Reader对象。 Library类则包含了一些Book对象和BorrowRecord对象,以及一些方法来管理这些对象。在这个示例中,Book和Reader之间是关联关系,BorrowRecord和Book、Reader之间则是聚合关系。 当然,这只是一个简单的示例,实际上您需要根据具体的需求来设计您的类图。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值