UVA 230(p136)----Borrowers
2016-02-25 22:41
211 查看
#include<map> #include<cstdio> #include<vector> #include<iostream> #include<algorithm> #define debu using namespace std; struct point { string bk,wr; }; vector<point> lt; map<string,int> name; int cmp(point a,point b) { if(a.wr==b.wr) return a.bk<b.bk; else return a.wr<b.wr; } int Find(int p) { for(int i=p; i>=0; i--) if(name[lt[i].bk]==2) return i; return -1; } int main() { #ifdef debug freopen("in.in","r",stdin); // freopen("out.out","w",stdout); #endif // debug string st; while(getline(cin,st)) { if(st=="END") break; int l=st.length(); int p1=st.find_last_of('"'); int p2=st.find_last_of('"'); point u; u.bk=st.substr(0,p1+1); u.wr=st.substr(p2+1); lt.push_back(u); } sort(lt.begin(),lt.end(),cmp); for(int i=0; i<lt.size(); i++) name[lt[i].bk]=2; while(getline(cin,st)) { if(st=="END") break; if(st[0]!='S') { int i,flag=0; int p1=st.find_first_of('"'); int l=st.length(); string tmp; tmp=st.substr(p1); if(st[0]=='B') name[tmp]=-1; else name[tmp]=1; } else { for(int i=0; i<lt.size(); i++) { if(name[lt[i].bk]==1) { int p=Find(i); if(p!=-1) cout<<"Put "<<lt[i].bk<<" after "<<lt[p].bk<<endl; else cout<<"Put "<<lt[i].bk<<" first"<<endl; name[lt[i].bk]=2; } } cout<<"END"<<endl; } } return 0; }题目地址:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=4&page=show_problem&problem=166
相关文章推荐
- JSBinding+SharpKit / 菜单介绍
- 【PHP】织梦仿站学习笔记(一)
- max-width
- RecycleView
- 黄聪:MYSQL5.6缓存性能优化my.ini文件配置方案
- 对于老师问卷调查中若干问题的回答
- CSS水平/垂直居中方法一览
- My架构师之路
- 关于iOS多线程
- UVA 225(p214)----Golygons
- StarUML2 全平台破解方法
- scala 学习第二章 函数
- jquery笔记
- 喊啥--RelationMap
- ubuntu 查看进程pid以及查看进程占用内存
- rootkit技术
- Linux input子系统分析
- Linux input子系统分析
- Linux input子系统分析
- mysql中的过程和函数