UVA 230(p136)----Borrowers

来源:互联网 发布:企业管理优化建议 编辑:程序博客网 时间:2024/05/21 19:43
#include<map>#include<cstdio>#include<vector>#include<iostream>#include<algorithm>#define debuusing 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
0 0