- #include
- #include
- #include
- #include
- using namespacestd;
- structnode
- {
- charname[1000];
- int parameter;
- < span style="margin:0px; padding:0px; border:none; color:black; background-color:inherit"> int priority;
- < span style="margin:0px; padding:0px; border:none; color: black; background-color:inherit">intnum;//Something went wrong here. . . It should be sorted in order. . . Similar to the question in the queue done by HDU last time, li>
- friendbooloperator<(nodea,nodeb)
- {
- if(b.priority== a.prio rity)
- < span style="margin:0px; padding:0px; border:none; color:black; background-color:inherit">return b.num< a .num;
- return b.priority
- };
- i ntmain()
- {
- priority_queue
q; - charstr[100];
- node temp;
- int num=0;
- while(~scanf(“%s”,str))
- {
- if(strcmp(str,“GET”)==0)
- {
- if(!q.empty())
- {
- temp = q.top() ;
- printf(“%s %d
“,temp.name,temp.parameter) ; - q.pop();
- else
- printf (“EMPTYQUEUE!
“); - else
- {
- scanf(“%s%d%d”,temp.name,&temp.parameter,&temp.priority); li>
- temp.num=num++;
-
q.push(temp); - < /li>
- }
- #include
- #include
- #include
- #include
- usingnamespace std;
- struct node
- {
- char name[1000];
- int parameter;
- int priority;
- int num; //这里出错了。 . .应该加个先后顺序排序。 . .类似上次HDU做的队列里的一题,
- friend bool operator<(node a,node b)
- {
- if(b.priority == a.priorit y)
- return b.num < a.num;
- return b.priority < a.priority;
- }
- };
- int main()
- {
- priority_queue
q; - char str[100];
- node temp;
- int num=0;
- while(~scanf(“%s”,str))
- {
- if(strcmp(str,“GET”)==0)
- {
- if(!q.empty())
- {
- temp = q.top();
- printf(“%s %d
” ,temp.name,temp.parameter); - q.pop();
- }
- else
- printf(“EMPTY QUEUE!
“); - }
- else
- {
- scan f(“%s %d %d”,temp.name,&temp.parameter,&temp.priority);
- temp.num=num++;
- q.push(temp);
- }
- }
- }