1.STL栈
hdu 1237 ‘简单计算器’
2.STL 优先队列 priority_queue
hdu 1873 看病要排队
#include<iostream> #include<queue> //加这个文件是因为杭电的oj不行 #include<string> using namespace std; struct Node{ int n, p; bool operator < (const Node &t) const { if (p == t.p) return n > t.n; return p < t.p; } }node; int main() { int n, id, doc; string temp; //没有输入scanf返回-1 while (~scanf("%d", &n)) { id = 0; priority_queue<Node> q[3]; while (n--) { cin>>temp; if (temp == "IN") { scanf("%d%d", &doc, &node.p); node.n = ++id; q[doc - 1].push(node); }else { scanf("%d", &doc); if (q[doc - 1].empty()) cout << "EMPTY" << endl; else { node = q[doc - 1].top(); q[doc - 1].pop(); cout << node.n<<endl; } } } } return 0; }
原文地址:https://www.cnblogs.com/zyyz1126/p/11806476.html
时间: 2024-11-05 23:30:44