zoukankan      html  css  js  c++  java
  • hdu1509 Windows Message Queue

    运算符重载

    题目

    #include<stdio.h>
    #include<iostream>
    #include<queue>
    #include<vector>
    #include<string>
    #include<algorithm>
    using namespace std;
    
    
    struct node{
        string name;
        int par,pri,id;
        friend bool operator< (node a,node b){
            if(a.pri==b.pri)
                return a.id >b.id;
                else return a.pri >b.pri;
        }
    };
    
    
    int main()
    {
        priority_queue <node> que;
        char a[5];
        int i=0;
        while(~scanf("%s",a))
        {
            if(a[0]=='G')
            {
                if(que.empty())
                    printf("EMPTY QUEUE!
    ");
                else
                {
                    node m = que.top();
                    //printf("%s %d
    ",m.name,m.par);
                    cout<<m.name<<" "<<m.par<<endl;
                    que.pop();
                }
            }
            if(a[0]=='P')
            {
                node t;
               // scanf("%s%d%d",t.name,&t.par,&t.pri);
               cin>>t.name>>t.par>>t.pri;
                t.id=i++;
                que.push(t);
            }
        }
    
    
        return 0;
    }


  • 相关阅读:
    自己总结的Java归并排序代码
    SpringDataJpa
    多态
    向上转型向下转型
    python面向对象装饰器
    Apache
    git
    μWSGI
    虚拟环境
    软件仓库(持续更新中)
  • 原文地址:https://www.cnblogs.com/qie-wei/p/12094131.html
Copyright © 2011-2022 走看看