1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| #include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #include<string> #include<queue> using namespace std; class bingren { public: int id; int youxianji; friend bool operator < (const bingren &a,const bingren &b) //比较奇怪的一个地方,只有加上const 才可以过,也可以直接(bingren a,bingren b); { if(a.youxianji!=b.youxianji) return a.youxianji<b.youxianji; else return a.id>b.id; } }; int num=0; int main() { int N; while(cin>>N) { num=0; priority_queue<bingren> q[4]; string s1; int a,b; while(N--) { cin>>s1; if(s1=="IN") { cin>>a>>b; bingren tt; num++; tt.youxianji=b; tt.id=num; q[a].push(tt); //队列入队时push,不是input } else { cin>>a; if(!q[a].empty()) { bingren tm=q[a].top(); q[a].pop(); cout<<tm.id<<endl; } else { cout<<"EMPTY"<<endl; } } } } return 0; }
|