题目:http://acm.hit.edu.cn/hoj/problem/view?id=1999
水题。练习优先队列,优先队列默认是大根堆,把他该做小根堆即可。
参考:http://blog.csdn.net/yidujinhuang/article/details/6868093
代码:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
priority_queue<int, vector<int>, greater<int> >q;
int t;
char op[20];
while(scanf(" %d",&t)!=EOF)
{
int n;
for(int i=0; i<t; i++)
{
scanf(" %s",op);
if(strcmp(op,"add") == 0)
{
scanf(" %d",&n);
q.push(n);
}
else if(strcmp(op,"query") == 0)
{
if(!q.empty())
{
printf("%d\n",q.top());
}
}
else if(strcmp(op,"delete") == 0)
{
if(!q.empty())
{
q.pop();
}
}
}
}
return 0;
}