您的位置:首页 > 其它

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: