#include<bits/stdc++.h>
using namespace std;
struct node{
int x,y;
float d;
};//记住格式
struct cmp{//******必须记住格式
bool operator()(node a,node b){
return a.d<b.d;//大顶堆
}
};
int main()
{
int n,m;//******格式一定要记住
priority_queue<node,vector<node>,cmp> q;//没有括号 两侧全是比较号
string str;
cin>>n;
getline(cin,str);//吸收换行符
for(int i=0;i<n;i++){
getline(cin,str);
if(str=="Pop"){
if(q.empty()) cout<<"empty"<<endl;//可以这样用
else
{
node t=q.top();q.pop();
cout<<t.x<<"+i"<<t.y<<endl;
cout<<"SIZE = "<<q.size()<<endl;//q.size()是允许的
}
}
else{
int pos1=str.find(" ",0);int pos2=str.find("+",0);
int k=0,kk=0;float s;
for(int i=pos1+1;i<=pos2-1;i++) k=k*10+str[i]-'0';
for(int i=pos2+2;i<str.length();i++) kk=kk*10+str[i]-'0';
s=sqrt(k*k+kk*kk);
q.push((node){k,kk,s});//格式要记住
cout<<"SIZE = " <<q.size()<<endl;//q.size()可以这样用
}
}
return 0;
}
北邮机试 复数——优先队列的使用
最新推荐文章于 2021-05-18 18:13:51 发布