紫书第五章习题 5-8 UVA230-图书馆管理

出处:https://blog.csdn.net/richr_wong/article/details/50193331

题目链接:https://vjudge.net/contest/231030#problem/H

题意本身还是比较好理解的,要注意的地方有

1.按照作者名字的字典序排序

2.归还的时候是无序的

利用set容器的性质做会好做一些

比较坑就是数据的输入,多练习一下就好了。


#include<iostream>  
#include<cstdio>  
#include<cstring>  
#include<set>  
#include<map>  
using namespace std;  
const int maxx=1010;  
typedef struct Node  
{  
    string book,name;  
    bool operator<(const struct Node &x)const  
    {  
        if(name!=x.name) return name<x.name;  
        return book<x.book;  
    }  
}node;  
int main()  
{  
    set<node> st;  
    map<string,string> mp;  
    string s;  
    node tnode;  
    int p;  
    while(getline(cin,s))  
    {  
        if(s[0]=='E') break;  
        p=s.find('"',1);  
        tnode.book=s.substr(0,p+1);  
        tnode.name=s.substr(p+5);  
        mp.insert(make_pair(tnode.book,tnode.name));  
        st.insert(tnode);  
    }  
    set<node> st1;  
    while(getline(cin,s))  
    {  
        if(s[0]=='E') break;  
        if(s[0]=='S')  
        {  
            set<node>::iterator it,it1;  
            for(it=st1.begin();it!=st1.end();it++)  
            {  
                cout<<"Put "<<it->book<<" ";  
                it1=st.lower_bound(*it);  
                if(st.empty()||it==st.begin()) cout<<"first"<<endl;  
                else cout<<"after "<<(--it1)->book<<endl;  
                st.insert(*it);  
            }  
            st1.clear();  
            cout<<"END"<<endl;  
        }  
        else  
        {  
            p=s.find('"');  
            string book=s.substr(p);  
            tnode.book=book;  
            tnode.name=mp[book];  
            if(s[0]=='B') st.erase(tnode);  
            else st1.insert(tnode);  
        }  
    }  
}  

猜你喜欢

转载自blog.csdn.net/JXUFE_ACMer/article/details/80454952