[AcWing 829] 模拟队列
2022/4/30 6:14:37
本文主要是介绍[AcWing 829] 模拟队列,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
点击查看代码
#include<iostream> using namespace std; const int N = 1e5 + 10; int q[N]; int l = 0, r = 0; void push(int x) { q[r] = x; r ++; } void pop() { l ++; } bool empty() { return l == r; } int query() { return q[l]; } int main() { int m; cin >> m; while (m --) { string str; cin >> str; if (str == "push") { int x; cin >> x; push(x); } if (str == "empty") { if (empty()) printf("YES\n"); else printf("NO\n"); } if (str == "query") printf("%d\n", query()); if (str == "pop") pop(); } return 0; }
- 使用数组模拟队列
这篇关于[AcWing 829] 模拟队列的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-10-19TypeScript入门教程:轻松上手开发
- 2024-10-19TypeScript进阶:从入门到初级应用教程
- 2024-10-18TypeScript入门:新手必读教程
- 2024-10-18Fullstack进阶:从入门到初级工程师的必经之路
- 2024-10-18Public API入门:新手必读教程
- 2024-10-18RSC入门:新手必读指南
- 2024-10-18Server Action入门:新手必读指南
- 2024-10-18Server Component入门:轻松掌握服务器组件基础
- 2024-10-18Server Component入门:新手必备指南
- 2024-10-18Trpc入门:新手必读教程