题目链接如下:
Online Judge文章来源:https://www.toymoban.com/news/detail-733641.html
代码如下:文章来源地址https://www.toymoban.com/news/detail-733641.html
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
// #define debug
struct book{
std::string title;
std::string author;
bool isExisted = true;
book(std::string _title, std::string _author): title(_title), author(_author){}
};
std::vector<book> vec, toReturn;
std::string str;
int loc;
std::map<std::string, int> mp;
bool cmp(const book &a, const book &b){
return a.author != b.author ? a.author < b.author : a.title < b.title;
}
int main(){
#ifdef debug
freopen("0.txt", "r", stdin);
freopen("1.txt", "w", stdout);
#endif
while (getline(std::cin, str) && str[0] != 'E'){
int i;
for (i = 1; i < str.size(); ++i){
if (str[i] == '"'){
break;
}
}
vec.push_back(book(str.substr(0, i + 1), str.substr(i + 5)));
}
sort(vec.begin(), vec.end(), cmp);
for (int i = 0; i < vec.size(); ++i){
mp[vec[i].title] = i;
}
while (getline(std::cin, str) && str[0] != 'E'){
if (str[0] == 'S'){
sort(toReturn.begin(), toReturn.end(), cmp);
for (int i = 0; i < toReturn.size(); ++i){
loc = mp[toReturn[i].title];
vec[loc].isExisted = true;
int j;
for (j = loc - 1; j >= 0; --j){
if (vec[j].isExisted){
break;
}
}
if (j < 0){
printf("Put %s first\n", toReturn[i].title.c_str());
} else{
printf("Put %s after %s\n", toReturn[i].title.c_str(), vec[j].title.c_str());
}
}
printf("END\n");
toReturn.clear();
} else{
std::string temp = str.substr(7);
if (str[0] == 'B'){
vec[mp[temp]].isExisted = false;
} else{
toReturn.push_back(vec[mp[temp]]);
}
}
}
#ifdef debug
fclose(stdin);
fclose(stdout);
#endif
return 0;
}
到了这里,关于230 - Borrowers (UVA)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!