STL——呵呵型自动机

Description
xiaofei最近研发了一个呵呵型自动机,该自动机能够同时处理n个队列。其中,队列的编号为1..n。给定m个操作,模拟该自动机的工作状态。
第一行有2个整数n,m(1≤n, m≤10,000),表示自动机能处理n个队列,接下来m行每行一条操作指令。
每条指令的格式如下:
这里写图片描述
在每条指令中,id的编号在1..n中,val的取值范围为-231~231。输入数据保证操作的第一条指令都是是INIT。(本题中的描述有误,POP中是输出一个,删除t个)

Input

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

Output

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

Sample Input
3 12
INIT
PUSH 1 100 1
POP 2 1
PUSH 3 300 1
PUSH 1 200 1
PUSH 2 -5 1
POP 2 1
PUSH 2 -10 1
POP 1 1
INIT
PUSH 1 7 1
POP 1 1
Sample Output
NULL
-5
100
7
HINT

用STL的queue容易解决

Append Code


AC代码

#include <iostream>
#include <queue>
using namespace std;
queue<int> p[10001];

int main()
{
    int k,n;
    while(cin>>k)
    {
        cin>>n;
        for(int i=0; i<n; i++)
        {
            string s;
            cin>>s;
            if(s=="INIT")
            {
                for(int j=1; j<=n; j++)
                {
                    while(!p[j].empty())
                        p[j].pop();
                }
            }
            else if(s=="PUSH")
            {
                int m,g;
                long long int t;
                cin>>m>>g>>t;
                for(int s=0; s<t; s++)
                {
                    p[m].push(g);
                }
            }
            else if(s=="POP")
            {
                int m,t;
                cin>>m>>t;
                if(!p[m].empty())
                {
                    cout<<p[m].front()<<endl;
                    for(int s=0; s<t; s++)
                        p[m].pop();
                }
                else
                    cout<<"NULL"<<endl;
            }
        }
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/fighting123678/article/details/80035979