标签:
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5424 Accepted Submission(s):
2225
#include<iostream> #include<cstdio> #include<cstring> #include<queue> using namespace std; struct node { friend bool operator<(node n1,node n2) { if(n1.priority==n2.priority) return n1.id>n2.id; else return n1.priority<n2.priority; } int id; int priority; }; int main() { int t; while(~scanf("%d",&t)) { int i,a,b,k=1; char s[5]; priority_queue<node>q1; priority_queue<node>q2; priority_queue<node>q3; struct node p; while(t--) { scanf("%s",s); if(s[0]==‘I‘) { scanf("%d%d",&a,&b); if(a==1) { p.id=k++; p.priority=b; q1.push(p); } if(a==2) { p.id=k++; p.priority=b; q2.push(p); } if(a==3) { p.id=k++; p.priority=b; q3.push(p); } } if(s[0]==‘O‘) { scanf("%d",&a); if(a==1) { if(!q1.empty()) { p=q1.top(); printf("%d\n",p.id); q1.pop(); } else printf("EMPTY\n"); } if(a==2) { if(!q2.empty()) { p=q2.top(); printf("%d\n",p.id); q2.pop(); } else printf("EMPTY\n"); } if(a==3) { if(!q3.empty()) { p=q3.top(); printf("%d\n",p.id); q3.pop(); } else printf("EMPTY\n"); } } } } return 0; }
标签:
原文地址:http://www.cnblogs.com/cancangood/p/4430125.html