UVa 230 Borrowers
2016-05-05 16:07
423 查看
#include<iostream> #include<cstdio> #include<string> #include<map> #include<sstream> #include<algorithm> #include<vector> #include<queue> #include<set> #include<cstring> #include<stack> #include<iomanip> #include<math.h> using namespace std; typedef struct { string author; int status; }book; vector<string> name; map<string,book> str2book; bool compare(const string &a,const string &b) { if(str2book[a].author!=str2book[b].author) return str2book[a].author<str2book[b].author; else return a<b; } int main() { string s; book temp; while(getline(cin,s)) { if(s=="END") break; int index1=s.find_last_of("\""); string book_name=s.substr(0,index1+1); temp.author=s.substr(index1+1); temp.status=1; str2book[book_name]=temp; name.push_back(book_name); } sort(name.begin(),name.end(),compare); string temp2; while(cin>>s) { if(s=="END") break; else if(s=="BORROW") { getchar(); getline(cin,temp2); str2book[temp2].status=0; } else if(s=="RETURN") { getchar(); getline(cin,temp2); str2book[temp2].status=-1; } else if(s=="SHELVE") { int j; for(int i=0;i<name.size();i++) { if(str2book[name[i]].status==-1) { for(j=i-1;j>=0;j--) { if(str2book[name[j]].status==1) break; } if(j==-1) { cout<<"Put "<<name[i]<<" first"<<endl; } else { cout<<"Put "<<name[i]<<" after "<<name[j]<<endl; } str2book[name[i]].status=1; } } cout<<"END"<<endl; } } return 0; }
相关文章推荐
- K3/ERP、fineprint8.0版cology8.1最新出炉JAVA功能越来越Fineport8.0
- 内存管理-2
- JVM类加载机制详解(一)JVM类加载过程
- 转:架构师实践日|亿级短视频应用秒拍的架构实践
- Ruby--正则
- C#实现 Eval
- POJ1651 Multiplication Puzzle(相邻乘积之和最小,区间DP)
- 内存管理-1
- virtualbox桥接网络配置--CentOS
- Java构造和解析Json数据的两种方法详解一
- Swift4
- ApachePOI组件操作Excel,制作报表(一)
- Objective-C中的Block
- c语言中变量作用域的区别
- jquery—multiSelect 一个页面多个下拉
- 在iPhone开发中实现解压缩gzip
- Android自定义软键盘
- My97DatePicker日期控件总结
- 莆田系医院名单
- NUI控件扩展