题解 | #复数集合#

复数集合

http://www.nowcoder.com/questionTerminal/abdd24fa839c414a9b83aa9c4ecd05cc

#include "cstdio"
#include "queue"
using namespace std;
#include "string"
struct complex{
    int re;
    int im;
};
bool operator < (complex lhs,complex rhs){
    //lhs的模<rhs的模,左边是父亲,右边是孩子
    return lhs.re*lhs.re+lhs.im*lhs.im <rhs.re*rhs.re+rhs.im*rhs.im;
}
int main(){
    int n;
    priority_queue<complex> queue;
    scanf("%d",&n);
    for (int i = 0; i < n; ++i) {
        char action[30];
        scanf("%s",action);
        string action1=action;
        if (action1=="Pop"){
            if (queue.empty()){
                printf("empty\n");
            } else{
                printf("%d+i%d\n",queue.top().re,queue.top().im);
                queue.pop();
                printf("SIZE = %d\n",queue.size());
              
            }
        } else if (action1 =="Insert"){
            int re,im;
            scanf("%d+i%d",&re,&im);//格式化读取
            complex c;
            c.re=re;
            c.im=im;
            queue.push(c);
            printf("SIZE = %d\n",queue.size());

        }
    }

}
全部评论
好,和我的一模一样
点赞 回复 分享
发布于 2023-04-06 21:05 山东

相关推荐

牛客83700679...:简历抄别人的,然后再投,有反馈就是简历不行,没反馈就是学历不行,多投多改只要技术不差机会总会有的
点赞 评论 收藏
分享
06-25 09:33
厦门大学 Java
球球别拷打俺了:现在日常估计没啥hc了,等到八月多估计就慢慢有了。双九✌🏻不用焦虑的
投递快手等公司7个岗位
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务