1 Star 0 Fork 0

conquer code/Algorithm

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
5.4.1-L-B3616.cpp 632 Bytes
一键复制 编辑 原始数据 按行查看 历史
conquer code 提交于 2025-11-29 18:29 +08:00 . 5.4.1-L-B3616
#include<iostream>
using namespace std;
//创建队
const int N=1e5+10;
int q[N],h,t;
//入队
void push(int x)
{
q[++t]=x;
}
//出队
void pop()
{
h++;
}
//查询队首元素
int query()
{
return q[h+1];
}
//有效元素个数
int size()
{
return t-h;
}
int main()
{
int n;cin>>n;
while(n--){
int op;cin>>op;
if(op==1){
int i;cin>>i;
push(i);
}
else if(op==2){
if(size()){
pop();
}
else{
cout<<"ERR_CANNOT_POP"<<endl;
}
}
else if(op==3){
if(size()){
cout<<query()<<endl;
}
else{
cout<<"ERR_CANNOT_QUERY"<<endl;
}
}
else{
cout<<size()<<endl;
}
}
return 0;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/conquer-code123/algorithm.git
git@gitee.com:conquer-code123/algorithm.git
conquer-code123
algorithm
Algorithm
master

搜索帮助