SDUT 双向队列(队列)

来源:互联网 发布:知乐的肉小说有哪些 编辑:程序博客网 时间:2024/05/22 16:48
#include<iostream>#include<cstdio>#include<string>#include<cstring>using namespace std;int main(){    int a[30000],n,m=11000,data;    int l=0,r=m,i=0;    cin>>n;    string str;    for(int j=1;j<=n;j++)    {        cin>>str;        if(str=="LIN")        {            cin>>data;            a[--l]=data;        }        else if(str=="RIN")        {            cin>>data;            a[++r]=data;        }        else if(str=="LOUT")        {            if(l!=m)            cout<<a[l++]<<endl;            //cout<<l<<endl;            else                cout<<j<<" "<<"ERROR"<<endl;        }        else if(str=="ROUT")        {            if(r!=m)            cout<<a[r--]<<endl;            else                cout<<j<<" "<<"ERROR"<<endl;        }    }    return 0;}

0 0
原创粉丝点击