uva 230
来源:互联网 发布:金山软件拆分 编辑:程序博客网 时间:2024/05/01 20:20
原题
也是纯模拟题, 远没有上次高尔夫球赛问题复杂..
就构造一个Book结构, 把涉及的变量都加进去, 除了title, author还有一个state
注意有三种state, (一开始以为borrow指令是无意义的, 其实还是有影响的, 借出去的书遍历的时候需要直接跳过了)
#include <iostream>#include <cstdio>#include <cstdlib>#include <algorithm>#include <string>#include <cstring> #include <vector>#include <set>#include <stack>#include <queue>#include <cmath>#include <deque> #include <map>#include <cassert>#include <iomanip>#include <list>using namespace std;const int MAXN = 170;typedef long long LL;/*uva 230*/const int notBorrowed = 0;const int isBorrowed = 1;const int isReturned = 2;struct Book{string title;string author;int state;Book(){ state = notBorrowed; }Book(string _title, string _author){title = _title;author = _author;state = notBorrowed;}};bool operator<(const Book & b1,const Book & b2){if( b1.author!=b2.author ){return b1.author < b2.author;}return b1.title < b2.title;}vector<Book> shelve;string str;char input[MAXN];Book & Find(const string & title){int i;for(i=0; i<shelve.size(); i++){if( shelve[i].title==title ){break;}}return shelve[i];}int main(){//freopen("input2.txt","r",stdin);string title, cmd,author;shelve.clear();while( cin>>input[0] && input[0]!='E' ){fgets(input+1,MAXN,stdin);input[strlen(input)-1] = '\0';char * ptr = strstr(input," by ");ptr[0] = '\0';title = input;author = (ptr+4);shelve.push_back(Book(title,author));}while( cin>>cmd && cmd!="END" ){if( cmd=="BORROW" ){getchar();getline(cin,title);Find(title).state = isBorrowed;}else if( cmd=="RETURN" ){getchar();getline(cin,title);Find(title).state = isReturned;}else if( cmd=="SHELVE" ){int lastBook = -1;sort(shelve.begin(),shelve.end(),less<Book>());for(int i=0; i<shelve.size(); i++){//cout << shelve[i].title << "---" << shelve[i].author << " : " << shelve[i].state << endl;if( shelve[i].state==notBorrowed ){lastBook = i;}else if( shelve[i].state==isBorrowed ){continue;}else if( shelve[i].state==isReturned ){shelve[i].state = notBorrowed;if( lastBook<0 ){// put firstcout << "Put " << shelve[i].title << " first" << endl;}else{// put after a bookcout << "Put " << shelve[i].title << " after " << shelve[lastBook].title << endl;}lastBook = i;}}cout << "END" << endl;}}return 0;}
0 0
- uva 230
- UVA 230
- UVA 230
- UVA 230
- Uva 230
- UVA - 230 Borrowers
- UVa 230 - Borrowers
- UVA - 230 Borrowers
- UVA-230 Borrowers
- Uva - 230 - Borrowers
- UVA 230 Borrowers
- UVA 230(p136)----Borrowers
- UVa 230 Borrowers
- uva 230 Borrowers
- UVA 230 Borrowers
- uva 230 Borrowers
- UVa 230 Borrowers
- uva
- New world,Good luck!
- 颠覆式前端UI开发框架:React
- Git客户端(Windows系统)的使用 本地仓库使用
- C语言sprintf使用出现段错误
- Delphi相关的几个博客
- uva 230
- mysql数据库索引的创建及使用
- 程序员面试宝典(第四版) —— 运算符问题 | a、b 交换与比较
- Android图形显示系统——上层显示2:硬件加速实现
- C++如何限制类对象只能静态分配或者只能只能动态分配
- 【思想感悟】——重新认识今目标
- Android Studio与Android SDK 在线更新的解决方案(1.3.2)
- Linux安装详解-配置ks.cfg实现自动安装过程
- Oracle建立表空间和用户