UVA 230(p136)----Borrowers

#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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值