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
#include
#include
#include
#include
using namespace std;
struct node{
friend bool operator<(node n1,node n2)
{
if(n1.priority!=n2.priority)
return n1.priority
}
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
priority_queue
priority_queue
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;
}