//踩坑 //1. 比较函数,多输入一个*,看来检查代码需要模块化检查 //2. 读懂题目,只要输入一次 n ! 后面都是指令 //3. #include<cstdio> #include <queue> #include<string> using namespace std; struct Comeplex{ //重构用到的类 a+bi int re; int im; }; bool operator < (Comeplex left, Comeplex right){ return left.re*left.re + left.im*left.im < right.im*right.im + right.re*right.re ; } int main() { int n; scanf("%d",&n); priority_queue<Comeplex> quq; //大跟堆,怎么大? 重构函数 give "<" 比较复数! for(int i=0;i<n;i++){ char str1[10]; scanf("%s",str1); string str11 = str1; //*********弹出 if(str11=="Pop"){ //****操纵1:弹出, 1 空不谈,2 不空的弹出 if(quq.empty()){ //队列空 quq.empty() printf("empty\n"); } else{ printf("%d+i%d\n",quq.top().re,quq.top().im); quq.pop(); printf("SIZE = %d\n", quq.size()); } } //*********插入操作 else if(str11=="Insert"){ //quq.push() 插入操作 int re; int im; scanf("%d+i%d",&re,&im); //特别的读入方式 Comeplex a; a.im=im; a.re=re; quq.push(a); printf("SIZE = %d\n", quq.size()); } } }