这个题大体思路是用一个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;
}
}
}