周赛(2)——双向队列

来源:互联网 发布:淘宝客怎么找佣金高的 编辑:程序博客网 时间:2024/06/06 11:37
#include <iostream>#include <deque>#include <cstring>#include <cstdio>using namespace std;int main(){    //freopen("d:\\my1.txt","r",stdin);    //freopen("d:\\aaa.txt","w",stdout);    char s[10];    int wrong[10005];    int n,x,count=0,k=0;    cin>>n;    int j;    deque <int> c;    deque <int> ::iterator pos;    while(n--)    {        cin>>s;        if(!(strcmp(s,"LIN")))        {            cin>>x;            c.push_front(x);            count++;        }        else if(!(strcmp(s,"RIN")))        {            cin>>x;            c.push_back(x);            count++;        }        else if(!(strcmp(s,"LOUT")))        {            if(c.empty())            {                wrong[k++]=++count;            }            else            {                c.pop_front();                count++;            }        }        else if(!(strcmp(s,"ROUT")))        {            if(c.empty())            {                wrong[k++]=++count;            }            else            {                c.pop_back();                count++;            }        }        else wrong[k++]=++count;    }    j=0;    for (pos=c.begin();pos!=c.end();pos++)        {            if(j<c.size()-1) cout<<*pos<<" ";            else cout<<*pos;        }    cout<<endl;    for(int i=0;i<=k-1;i++)    {        cout<<wrong[i]<<" ERROR"<<endl;        //if(i!=(k-1)) cout<<endl;    }}


http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1466

STL无敌了= =。。。PE党伤不起= =