题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1509
题目大意:每一次输入都有序号和优先级,优先级小的先输出,优先级相同的话则序号小的先输出!第一次用优先队列,暂时对优先队列的理解即:输出最小的~AC代码,供参考!
1 #include <iostream> 2 #include <cstdio> 3 #include <queue> 4 using namespace std; 5 6 struct node 7 { 8 char str[100]; 9 int a,b,c; 10 bool friend operator <(node n1,node n2) 11 { 12 if(n1.b==n2.b) 13 { 14 return n1.c>n2.c; 15 } 16 return n1.b>n2.b; 17 } 18 } s,ss; 19 20 21 int main () 22 { 23 //node q; 24 priority_queue<node>Q; 25 int k=1; 26 char ch[10]; 27 while (cin>>ch) 28 { 29 if (ch[0]=='G') 30 { 31 if (!Q.empty()) 32 { 33 s=Q.top(); 34 Q.pop(); 35 printf("%s %d ",s.str,s.a); 36 } 37 else 38 printf("EMPTY QUEUE! "); 39 } 40 else 41 { 42 scanf("%s%d%d",s.str,&s.a,&s.b); 43 s.c=k++; 44 Q.push(s); 45 } 46 } 47 return 0; 48 }