您的位置:首页 > 其它

UVa 230 Borrowers

2016-05-05 16:07 423 查看
#include<iostream>
#include<cstdio>
#include<string>
#include<map>
#include<sstream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<cstring>
#include<stack>
#include<iomanip>
#include<math.h>
using namespace std;

typedef struct
{
string author;
int status;
}book;

vector<string> name;
map<string,book> str2book;

bool compare(const string &a,const string &b)
{
if(str2book[a].author!=str2book[b].author)
return str2book[a].author<str2book[b].author;
else
return a<b;
}

int main()
{
string s;
book temp;
while(getline(cin,s))
{

if(s=="END")
break;
int index1=s.find_last_of("\"");
string book_name=s.substr(0,index1+1);
temp.author=s.substr(index1+1);
temp.status=1;
str2book[book_name]=temp;
name.push_back(book_name);
}
sort(name.begin(),name.end(),compare);
string temp2;
while(cin>>s)
{
if(s=="END")
break;
else if(s=="BORROW")
{
getchar();
getline(cin,temp2);
str2book[temp2].status=0;
}
else if(s=="RETURN")
{
getchar();
getline(cin,temp2);
str2book[temp2].status=-1;
}
else if(s=="SHELVE")
{
int j;
for(int i=0;i<name.size();i++)
{
if(str2book[name[i]].status==-1)
{
for(j=i-1;j>=0;j--)
{
if(str2book[name[j]].status==1)
break;
}

if(j==-1)
{
cout<<"Put "<<name[i]<<" first"<<endl;
}
else
{
cout<<"Put "<<name[i]<<" after "<<name[j]<<endl;
}
str2book[name[i]].status=1;
}
}
cout<<"END"<<endl;
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: