Light OJ 1212

来源:互联网 发布:怎么去痘印 知乎 编辑:程序博客网 时间:2024/06/14 22:07

  万恶的模拟,逻辑关系不清醒,就会WA的。

记re为队尾,ft为队头,默认ft所在位置无元素,re所在位置有元素,所以按照这个逻辑关系模拟下去,就AC了。

#include<iostream>#include<cstdio>#include<cstring>using namespace std;int a[30];char s[20];int main(){    int T,ca=0,i,j;    int re,ft,Q,len,num;    cin>>T;    while(T--)    {        ca++;        re=ft=15;        cin>>len>>Q;        cout<<"Case "<<ca<<":"<<endl;        for(i=0;i<Q;i++)        {           cin>>s;           if(s[1]=='u')           {               cin>>num;               if(s[4]=='L')               {                   if(re-ft>=len) cout<<"The queue is full"<<endl;                   else  {                         a[ft]=num;ft--;                         cout<<"Pushed in left: "<<num<<endl;                        }               }               else               {                   if(re-ft>=len) cout<<"The queue is full"<<endl;                   else {re++;                        a[re]=num;                   cout<<"Pushed in right: "<<num<<endl;                   }               }           }           else           {               if(s[3]=='L')               {                   if(ft==re) cout<<"The queue is empty"<<endl;                   else  {                     cout<<"Popped from left: "<<a[ft+1]<<endl;                     ft++;                   }               }               else               {                   if(ft==re)  cout<<"The queue is empty"<<endl;                   else {                    cout<<"Popped from right: "<<a[re]<<endl;                    re--;                   }               }           }        }    }    return 0;}


0 0