题解 | #复数集合#

复数集合

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")

全部评论

相关推荐

点赞 评论 收藏
分享
Kunnnnnnn:看这公司23年就成立了啊 还没倒闭呢
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务