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
- Light OJ 1212
- light oj
- light oj
- Light OJ
- Light OJ
- Light OJ 1000
- Light OJ 1001
- Light OJ 1008
- Light OJ 1022
- Light OJ 1015
- Light OJ 1042
- light oj 1128
- Light OJ 1055 BFS
- Light OJ Beginners Problems
- Light OJ Basic Geometry
- Light OJ Basic Math
- light oj 1124
- Light OJ 1012
- Opengl 基础概念
- Linux中.png文件无法拷贝到U盘中的解决办法
- java中String、StringBuilder、StringBuffer的区别
- github常用指令
- MAC 配置安装 zsh与oh-my-zsh
- Light OJ 1212
- HDU1394 Minimum Inversion Number 【线段树】+【逆序数】
- 兹桩棕醉罪自琢阻诅
- 数据存储preferenceActivity
- 如果生梁这位时号给狼
- 数据库设计原则
- shell脚本操作数据库
- android获取string.xml的值
- 浅谈地信业之困惑与机会_孙玉国