poj 2259

编程入门 行业动态 更新时间:2024-10-25 16:21:23

<a href=https://www.elefans.com/category/jswz/34/1766382.html style=poj 2259"/>

poj 2259

题意:给出几组数据, 将他们插入队列, 当某个数据插入时,前面有他们一组的数据, 则插入到它所属组数据的后面,出队时按顺序出队就行了。
#include <iostream>
#include <queue>
#include <map>
#include <cstdio>
#include <cstring>using namespace std;const int N = 1005;
int num[N];int t;
int n;int main()
{char str[20];int a;int q = 1;while( scanf("%d", &t) != EOF){if(t == 0)break;queue<int>que[N], qu;map<int, int>Map;memset(num, 0, sizeof(num));for(int i = 0; i < t; i++){scanf("%d", &n);for(int j = 0; j < n; j++){scanf("%d", &a);Map[a] = i;}}int k;printf("Scenario #%d\n", q++);while(scanf("%s", str)!= EOF){if(strcmp(str, "STOP") == 0) {printf("\n");break;}if(strcmp(str, "ENQUEUE")== 0){scanf("%d", &a);k = Map[a];que[k].push(a);if(num[k] == 0){qu.push(k);num[k] = 1;}}else{printf("%d\n", que[qu.front()].front());que[qu.front()].pop();if(que[qu.front()].empty()) {num[qu.front()] = 0;qu.pop();}}}}return 0;
}

更多推荐

poj 2259

本文发布于:2024-02-25 21:40:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1700373.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:poj

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!