UVA 230

来源:互联网 发布:淘宝怎么刷単赚钱 编辑:程序博客网 时间:2024/05/01 08:48
#include<iostream>#include<vector>#include<string>#include<type_traits>#include<sstream>#include<tuple>#include<bitset>#include<regex>#include<set>#include<queue>#include<map>using namespace std;typedef struct book{string name;string author;bool flag;}book;bool compare(book a,book b){if (a.author != b.author) return a.author < b.author;return a.name < b.name;}int main(){string s;vector<book> shv;while (getline(cin, s)){if (s == "END") break;book temp;int index1 = s.find_last_of("\"");temp.name = s.substr(0,index1+1);temp.author = s.substr(index1+5);temp.flag = true;shv.push_back(temp);}sort(shv.begin(),shv.end(),compare);map<string, int> str2int;for (int i = 0; i < shv.size(); i++){string name = shv[i].name;str2int[name] = i;}vector<string> result;vector<book> re_book;while (getline(cin, s)){if (s == "END") break;else if (s == "SHELVE"){sort(re_book.begin(),re_book.end(),compare);for (int i = 0; i < re_book.size(); i++){string name = re_book[i].name;int pos = str2int[name];shv[pos].flag = true;int cur_pos;for (cur_pos = pos - 1; cur_pos >= 0; cur_pos--){if (shv[cur_pos].flag) break;}string res;if (cur_pos >= 0){res = "Put " + name + " after " + shv[cur_pos].name;}else{res = "Put " + name + " first";}result.push_back(res);}for (int i = 0; i < result.size(); i++) cout << result[i] << endl;cout << "END" << endl;re_book.clear();result.clear();}else{int index1;index1 = s.find_first_of("\"");string op = s.substr(0,index1-1);string name = s.substr(index1);int pos = str2int[name];if (op == "RETURN"){book temp;temp.name = name;temp.author = shv[pos].author;re_book.push_back(temp);}else if (op=="BORROW"){shv[pos].flag = false;}}}//system("pause");return 0;}

原创粉丝点击