题解 | #复数集合#
复数集合
https://www.nowcoder.com/practice/abdd24fa839c414a9b83aa9c4ecd05cc
#include <iostream>
#include <cmath>
#include <string>
#include <queue>
using namespace std;
struct Complex{
int re;
int im;
};
bool operator <(Complex lhs, Complex rhs){
return pow(lhs.re,2) + pow(lhs.im,2) < pow(rhs.re,2) + pow(rhs.im,2);
}
int main() {
priority_queue<Complex> myque;
int n;
scanf("%d",&n);
for(int i=0;i<n;++i){
char x[30];
scanf("%s",x);
if(x[0]=='P'){
if(myque.empty()) printf("empty\n");
else{
printf("%d+i%d\n",myque.top().re,myque.top().im);
myque.pop();
printf("SIZE = %d\n",myque.size());
}
}
else if(x[0] == 'I'){
int real,img;
scanf("%d+i%d",&real,&img);
Complex y;
y.re = real;
y.im = img;
myque.push(y);
printf("SIZE = %d\n",myque.size());
}
}
}
// 64 位输出请用 printf("%lld")
查看8道真题和解析