hdoj 4006The kth great number(优先级队列)

来源:互联网 发布:jackson json转对象 编辑:程序博客网 时间:2024/04/30 06:40

          很水的一道题……

#include<iostream>#include<cstdio>#include<queue>using namespace std;class cmp{public:      bool operator()(const int &a,const int &b)  const    {          return a>b;      }  };int main(){    int n, k, temp;    int i, j;    char c;    priority_queue<int, vector<int>, cmp> q;    while(    scanf("%d %d",&n, &k)!=EOF )    {        for( i=0;i<n;i++)        {            getchar();            scanf("%c",&c);            if( c=='I')            {                scanf("%d",&temp);                q.push(temp);                if( q.size()>k )                    q.pop();            }            else if( c=='Q')            {                printf("%d\n",q.top());            }        }        while( !q.empty())            q.pop();    }}