PTA 7-7 Windows消息队列
2017-10-25 01:01
351 查看
消息队列是Windows系统的基础。对于每个进程,系统维护一个消息队列。如果在进程中有特定事件发生,如点击鼠标、文字改变等,系统将把这个消息加到队列当中。同时,如果队列不是空的,这一进程循环地从队列中按照优先级获取消息。请注意优先级值低意味着优先级高。请编辑程序模拟消息队列,将消息加到队列中以及从队列中获取消息。
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <vector> #include <string> #include <queue> using namespace std; const int maxn = 1e5 + 10; struct Data { int x, id; Data(int xx, int i) : x(xx), id(i) {} bool operator < (const Data &temp) const { return x > temp.x; } }; char s[20], str[maxn][20]; int main() { int n, x, cnt = 0; priority_queue<Data> q; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%s", s); if (s[0] == 'P') { scanf("%s%d", str[++cnt], &x); q.push(Data(x, cnt)); } else { if (q.empty()) printf("EMPTY QUEUE!\n"); else { Data d = q.top(); q.pop(); printf("%s\n", str[d.id]); } } } return 0; }
相关文章推荐
- PTA-数据结构 5-26 Windows消息队列 (25分)
- PTA 7-7 Windows消息队列(25 分)
- PTA 7-7(排序) Windows消息队列(25 分) 25分代码 优先队列
- PTA 7-7(排序) Windows消息队列(25 分) 25分代码 优先队列
- 细说UI线程和Windows消息队列
- windows每个线程一个消息队列吗?
- windows 消息队列
- zoj 2724 Windows Message Queue(使用priority_queue容器模拟消息队列)
- Windows消息队列
- C#中使用Windows消息队列服务(MSMQ)简单示例
- Windows消息队列,UI线程,窗口以及消息处理方式总结
- Windows的消息队列与消息循环
- Windows消息队列,UI线程,窗口以及消息处理方式总结
- windows消息队列
- PHP消息队列rabbitmq——windows
- WinForm 和 Windows Service 通信 消息队列
- windows 消息队列Microsoft Message Queue (MSMQ)实例
- windows 消息队列
- 一篇很好的Windows消息队列的文章
- 5-26 Windows消息队列 (25分)