hdu 4006

本文介绍了一个使用C++实现的优先队列程序,通过输入输出操作处理整数数组,实现增删查操作并输出最大值。程序通过优先队列结构动态维护元素的顺序,有效提高了数据处理效率。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include<stdio.h>
#include<queue>
#include<iostream>
using namespace std;
struct node {
int num;
friend bool operator<(node a,node b) {
return a.num>b.num;
}
};
int main() {
int count,n,k,i;
char s[3];
while(scanf("%d%d",&n,&k)!=EOF) {
priority_queue<node>q;
node p;
count=0;
while(n--) {
scanf("%s",s);
if(s[0]=='I') {
scanf("%d",&i);
p.num=i;
   count++;
if(count<=k)
q.push(p);
else {
if(i>q.top().num) {
q.pop();
q.push(p);
}
}
}
else
printf("%d\n",q.top().num);
}
}
return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值