解题思路:
注意事项:
注意不满k个的时候,输出最大的
参考代码:
#include<iostream>
#include<set>
using namespace std;
int main(void)
{
int i,j;
int n,k,temp;
char ch;
while(cin>>n>>k)
{
multiset<int>st;
multiset<int>::iterator p;
for(i=0;i<n;i++)
{
cin>>ch;
if(ch=='I')
{
cin>>temp;
st.insert(temp);
}
else if(ch=='Q')
{
if(st.size()>=k)
{for(p=st.end(),j=0;j<k;p--,j++);
cout<<*p<<endl;
}
else
cout<<*(st.begin())<<endl;
}
}
}
return 0;
}
0.0分
1 人评分
C语言程序设计教程(第三版)课后习题11.8 (C语言代码)浏览:610 |
不会做的浏览:874 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:522 |
WU-输入输出格式练习 (C++代码)浏览:1080 |
2004年秋浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:1329 |
C语言程序设计教程(第三版)课后习题10.1 (C语言代码)浏览:530 |
C二级辅导-同因查找 (C语言代码)浏览:567 |
简单的a+b (C语言代码)浏览:462 |
2003年秋浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:615 |
平方数问题,oj一直是wrong answer浏览:739 |