POJ 1886简单模拟
来源:互联网 发布:ubuntu连打印机 编辑:程序博客网 时间:2024/05/21 21:34
http://poj.org/problem?id=1886
#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;}/*"The Canterbury Tales" by Chaucer, G."The Canterbury Taless" by Chaucer, B."Algorithms" by Sedgewick, R."The C Programming Language" by Kernighan, B. and Ritchiee, D."The C Programming Languag" by Kernighan, B. and Ritchiee, D."The D Programming Language" by Kernighan, B. and Ritchiee, D."A House for Mr. Biswas" by Naipaul, V.S."A Congo Diary" by Naipaul, V.S.ENDBORROW "Algorithms"BORROW "The C Programming Language"BORROW "The C Programming Languag"BORROW "The Canterbury Taless"SHELVERETURN "Algorithms"SHELVERETURN "The C Programming Languag"SHELVEBORROW "The C Programming Languag"BORROW "The Canterbury Taless"BORROW "A House for Mr. Biswas"RETURN "The Canterbury Taless"SHELVERETURN "The C Programming Language"RETURN "A House for Mr. Biswas"SHELVEENDans isENDPut "Algorithms" after "A House for Mr. Biswas"ENDPut "The C Programming Languag" after "The Canterbury Tales"ENDPut "The Canterbury Taless" firstENDPut "The C Programming Language" after "The Canterbury Tales"Put "A House for Mr. Biswas" after "A Congo Diary"END*//*"The Canterbury Tales" by Chaucer, G."Algorithms" by Sedgewick, R."The C Programming Language" by Kernighan, B. and Ritchie, D.ENDBORROW "Algorithms"BORROW "The C Programming Language"RETURN "Algorithms"RETURN "The C Programming Language"SHELVEENDans isPut "The C Programming Language" after "The Canterbury Tales"Put "Algorithms" after "The C Programming Language"END*//*"The Canterbury Tales" by Chaucer, G."Algorithms" by Sedgewick, R."The C Programming Language" by Kernighan, B. and Ritchie, D.ENDBORROW "Algorithms"BORROW "The C Programming Language"SHELVERETURN "Algorithms"SHELVEBORROW "The Canterbury Tales"RETURN "The C Programming Language"SHELVERETURN "The Canterbury Tales"SHELVE*//*ans isENDPut "Algorithms" after "The Canterbury Tales"ENDPut "The C Programming Language" firstENDPut "The Canterbury Tales" firstEND*/
0 0
- POJ 1886简单模拟
- POJ 2453 简单模拟
- POJ 2833 简单模拟
- poj 1573 简单模拟
- POJ 1013 (简单模拟)
- POJ 2996 简单模拟
- POJ 3032 简单队列模拟
- POJ 1017Packets---简单模拟
- POJ 2497 Strategies 简单模拟
- poj 1281(简单模拟题)
- poj 1590Palindromes 简单模拟
- POJ 1017 Packets 简单模拟
- POJ 3652 Persistent Bits 简单字符串模拟
- POJ 1573:Robot Motion:简单模拟
- poj 1281 MANAGER(简单模拟题)
- POJ 1132 Border(边界) 简单模拟
- poj 2190 简单模拟(ISBN)
- POJ 2000 Gold Coins(简单模拟)
- 微信公众号测试号申请及访问
- 404错误解决新思路
- Rabbitmq 流控
- 写个脚本生成库链接
- ubuntu16.04(2) -中文输入问题
- POJ 1886简单模拟
- iOS Design
- C++基础--面向对象
- git fetch git pull 区别
- 【Easy】26. Remove Duplicates from Sorted Array
- ubunt64位如何安装交叉编译环境
- Quartz 基本概念及原理
- 简单算法解决汉诺塔问题
- Android Design Support Library 兼容库使用详解