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;
}
#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
发布评论