当前位置:首页 > 编程笔记 > 正文
已解决

230 - Borrowers (UVA)

来自网友在路上 154854提问 提问时间:2023-10-31 15:35:02阅读次数: 54

最佳答案 问答题库548位专家为你答疑解惑

题目链接如下:

Online Judge

代码如下:

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
// #define debugstruct 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 debugfreopen("0.txt", "r", stdin);freopen("1.txt", "w", stdout);#endifwhile (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 debugfclose(stdin);fclose(stdout);#endifreturn 0;
}

查看全文

99%的人还看了

猜你感兴趣

版权申明

本文"230 - Borrowers (UVA)":http://eshow365.cn/6-28760-0.html 内容来自互联网,请自行判断内容的正确性。如有侵权请联系我们,立即删除!