#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
using namespace std;
struct book{
string author;
int status;
};
map<string, book> books;
vector<string> name;
bool compare(string a, string b){
if(books[a].author == books[b].author) return a < b;
else return books[a].author < books[b].author;
}
int main()
{
string x,z,m;
book y;
while(getline(cin,m)){
if(m == "END") break;
x = m.substr(0, m.find_last_of("\"")+1);
y.author = m.substr(m.find_last_of("\"")+1);
name.push_back(x);
books[x]= y;
}
sort(name.begin(), name.end(), compare);
for(int i = 0; i < name.size(); i++)
books[name[i]].status = 1;
while(cin >> x){
if(x == "END") break;
if(x == "BORROW"){
getchar();
getline(cin, z);
books[z].status = 0;
}
if(x == "RETURN"){
getchar();
getline(cin, z);
books[z].status = -1;
}
if(x == "SHELVE"){
for(int i = 0; i < name.size(); i++)
if(books[name[i]].status == -1){
int j;
for(j = i; j >= 0; --j)
if(books[name[j]].status == 1) break;
if(j > -1) cout << "Put " << name[i] << " after " << name[j] << endl;
else cout << "Put " << name[i] << " first" << endl;
books[name[i]].status = 1;
}
cout << "END" << endl;
}
}
return 0;
}
UVa230 - Borrowers
原创
©著作权归作者所有:来自51CTO博客作者wx5915393277dca的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
5-8 UVA 230 Borrowers图书管理系统
大体题意:1.这里我把BO
uva c语言 #include ci ios -
230,螺旋矩阵 II
给定一个正整数 n,生成一个包含 1 到 n^2 所有元素,且元素按顺时针顺序螺旋排列的正方形矩阵。示例:输
递归 if语句 i++ 顺时针 编程语言