Problem E: STL——呵呵型自动机

xiaoxiao2021-02-28  106

HomeWeb BoardProblemSetStandingStatusStatistics

Problem E: STL——呵呵型自动机

Time Limit: 8 Sec  Memory Limit: 128 MB Submit: 2284  Solved: 963 [ Submit][ Status][ Web Board]

Description

xiaofei最近研发了一个呵呵型自动机,该自动机能够同时处理n个队列。其中,队列的编号为1..n。给定m个操作,模拟该自动机的工作状态。 第一行有2个整数n,m(1≤n, m≤10,000),表示自动机能处理n个队列,接下来m行每行一条操作指令。 每条指令的格式如下: 指令 指令说明 INIT 将自动机初始化,此时所有的队列清空。 PUSH id val t 把t个整数val加入到编号id的队列的尾部。 POP id  t 输出并删除编号id的队列的前t个队首元素,如果队列为空,则输出“NULL”。   在每条指令中,id的编号在1..n中,val的取值范围为-2 31~2 31。输入数据保证操作的第一条指令都是是INIT。

Input

本题有多组输入数据,你必须处理到EOF为止。

Output

请对输入数据中每条POP指令的结果依次输出一行结果。

Sample Input

3 12 INIT PUSH 1 100 1POP 2 1PUSH 3 300 1PUSH 1 200 1PUSH 2 -5 1POP 2 1PUSH 2 -10 1POP 1 1INIT PUSH 1 7 1POP 1 1

Sample Output

NULL-51007

HINT

用STL的queue容易解决

Append Code

[ Submit][ Status][ Web Board]

한국어<   中文  فارسی  English  ไทย All Copyright Reserved 2010-2011 SDUSTOJ TEAM GPL2.0 2003-2011 HUSTOJ Project TEAM Anything about the Problems, Please Contact Admin:admin

#include <iostream> #include <queue> using namespace std; int main() { int m, n; while( cin >> n) { cin >> m; queue <int >Q[n+1]; for(int p = 0; p < m; p++ ) { string s; cin >> s; if(s == "INIT") for(int i = 0; i <= n; i++) while(!Q[i].empty()) Q[i].pop(); if(s == "POP" ) { int i, t; cin >> i >> t; if(Q[i].empty()) cout << "NULL" << endl; else { queue<int> q1; cout << Q[i].front() << endl; Q[i] = q1; } } if(s == "PUSH") { int i, j, t; cin >> i >> j >> t; for(int k = 0; k < t; k++) Q[i].push(j); } } } }
转载请注明原文地址: https://www.6miu.com/read-80105.html

最新回复(0)