队列和栈
来源:互联网 发布:重庆软件行业公司 编辑:程序博客网 时间:2024/05/16 15:53
栈
#include<cstdio>#include<stack>using namespace std;const int MAXN=1010;int n,target[MAXN];int main(){ while(~scanf("%d",&n)) { stack<int> s; int A=1,B=1; for(int i=1;i<=n;i++) scanf("%d",&target[i]); int ok=1; while(B<=n) { if(A==target[B]) { A++; B++; } else if(!s.empty()&&s.top()==target[B]) { s.pop(); B++; } else if(A<=n) s.push(A++); else { ok=0; break; } } printf("%s\n",ok?"Yes":"No"); } return 0;}<span style="color:#cc0000;"></span>
#include<cstdio>#include<queue>using namespace std;int main(){ int n; queue<int> q; scanf("%d",&n); for(int i=1;i<=n;i++) q.push(i); while(!q.empty()) { printf("%d ",q.front()); q.pop(); q.push(q.front()); q.pop(); } return 0;}
0 0
- 栈和队列--队列
- 【栈和队列】队列
- 栈、队列和优先队列
- 栈和队列(队列)
- 栈和队列--栈
- 【栈和队列】栈
- 栈和队列
- 栈和队列
- 表、栈和队列
- 栈和队列
- 栈和队列应用
- 栈和队列
- 栈和队列
- 栈和队列
- 栈和队列
- 栈和队列
- 队列和栈
- 栈和队列 小结
- Evaluate Reverse Polish Notation
- jquery实例-多张图片无缝滚动实现
- hdu-1856 More is better
- org/apache/commons/collections/map/ListOrderedMap不存在
- Java 进程通信
- 队列和栈
- 反思
- JSON
- php每日学习总结(6)
- My first Blog
- Vsphere中ESXi主机ssh开启的三种方法
- iOS 之 Block 的使用 (一)
- 十多个得过是广东省十多个高
- MFC 动态创建控件 字体设置问题