标签:
7 IN 1 1 IN 1 2 OUT 1 OUT 2 IN 2 1 OUT 2 OUT 1 2 IN 1 1 OUT 1
2 EMPTY 3 1 1
在看优先队列,感觉应该是作为一种工具使用的吧。。。。
#include<cstdio>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
struct node{
friend bool operator<(node n1,node n2)
{
if(n1.priority!=n2.priority)
return n1.priority<n2.priority;
else return n1.value>n2.value;
}
int priority;
int value;
};
int main()
{
int n,i,j,k,a,b;
char str[20];
node patient[2005];
while(scanf("%d",&n)!=EOF)
{
k=1;
priority_queue<node>doc1;
priority_queue<node>doc2;
priority_queue<node>doc3;
for(i=1;i<=n;i++)
{
scanf("%s",str);
if(strcmp(str,"IN")==0){
scanf("%d%d",&a,&b);
patient[k].priority=b;
patient[k].value=k;
if(a==1)doc1.push(patient[k]);
if(a==2)doc2.push(patient[k]);
if(a==3)doc3.push(patient[k]);
k++;
}
if(strcmp(str,"OUT")==0){
scanf("%d",&a);
if(a==1){
if(doc1.empty())printf("EMPTY\n");
else {
printf("%d\n",doc1.top().value);
doc1.pop();
}
}
if(a==2){
if(doc2.empty())printf("EMPTY\n");
else {
printf("%d\n",doc2.top().value);
doc2.pop();
}
}
if(a==3){
if(doc3.empty())printf("EMPTY\n");
else {
printf("%d\n",doc3.top().value);
doc3.pop();
}
}
}
}
}
return 0;
}
标签:
原文地址:http://blog.csdn.net/aaaaacmer/article/details/46239613