UVA230 Borrowers

本文介绍了一个图书管理系统的实现方法,利用C++语言通过map结构对图书进行分类管理,并实现了图书的借阅、归还及上架等功能。系统通过比较图书作者和名称来确保信息的准确性。

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

   这个题大体思路是用一个map将图书进行分类,把在书架上的,借走的,将要归还的分别分类,排序后进行查找即可。
#include<iostream>
#include<map>
using namespace std;
const int maxn = 10000 + 10;
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
struct haha
{
    string name,author;
    bool operator < (const haha& a) const
    {
        return author < a.author || author == a.author && name < a.name;
    }
}book[maxn];
int main()
{
    string s;
    int i, j, k;
    map<string,int>book2;
    for(i = 0;;i++){
        getline(cin,s);
        if(s[0] == 'E') break;
        int temp = 0;
        int k = s.find('"',1);
        book[i].name = s.substr(0,k+1);
        book[i].author = s.substr(k+5);
        book2[book[i].name] = 1;
    }
    int len = i;
    while(getline(cin,s)){
        if(s[0] == 'E') break;
        else if(s[0] == 'S'){
            sort(book,book+len);
            for(i = 0; i < len; i++){
                if(book2[book[i].name] == 0){
                    cout << "Put " << book[i].name << ' ';
                    for(j = i-1; j >= 0; j--)
                        if(book2[book[j].name] == 1) break;
                    if(j == -1) cout << "first\n";
                    else cout << "after " << book[j].name << endl;
                    book2[book[i].name] = 1;
                }
            }
            cout << "END\n";
        }
        else{
            int k = s.find('"');
            string ss = s.substr(k);
            if(s[0] == 'B') book2[ss] = -1;
            else book2[ss] = 0;
        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值