//土尔逊Torson 编写于2023/06/12 #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <cstdio> #include <queue> #include <string> using namespace std; struct Complex { int real; //实部 int imag; //虚部 Complex(int a,int b):real(a),imag(b) {} //题目中要求比较关系由复数的模决定,但代码中并没有使用复数的模来进行比较的,而是利用模的平方来进行比较的。 bool operator< (Complex c) const { //重载小于号 return real*real + imag*imag < c.real*c.real + c.imag*c.imag; } }; int main() { int n; while (scanf("%d", &n) != EOF) { priority_queue<Complex> myPriorityQueue; while (n--) { string str; cin >> str; if (str == "Pop") { if (myPriorityQueue.empty()) { printf("empty\n"); } else { Complex current = myPriorityQueue.top(); myPriorityQueue.pop(); printf("%d+i%d\n", current.real, current.imag); printf("SIZE = %d\n", myPriorityQueue.size()); } } else { int a, b; scanf("%d+i%d", &a, &b); myPriorityQueue.push(Complex(a, b)); printf("SIZE = %d\n", myPriorityQueue.size()); } } } system("pause"); return EXIT_SUCCESS; } // 64 位输出请用 printf("%lld")