POJ 1363(栈)
2015-11-16 22:36
399 查看
#include <iostream> #include "stdio.h" #include "stdlib.h" #include "string.h" #include "algorithm" #include <queue> #include <stack> #define N 100005 using namespace std; int main() { int n; int target[1005]; stack<int> s; while(scanf("%d", &n) != EOF && n) { while(scanf("%d", &target[1]) != EOF) { if(target[1] == 0) break; while(!s.empty()) s.pop(); for(int i=2; i <= n; i++) scanf("%d", &target[i]); int a = 1, b = 1, leap = 1; while(b <= n){ if( !s.empty() && s.top() == target[b] ) { b++; s.pop(); } //如果栈不为空且栈顶元素等于目标的元素 else if( a <= n ) { s.push(a++); } //如果不满足第一个条件且 火车未全部进栈 else { leap = 0; break; } } if( leap ) printf("Yes\n"); else printf("No\n"); } printf("\n"); } return 0; }
相关文章推荐
- 同样带来的是四道java笔试题
- 配置Java开发环境
- 南大软院大神养成计划(第一天;认识 DW)
- AVL树笔记(一):zig-zag,insert,find,predecessor,successor
- MySQL添加用户、删除用户与授权
- 程序员都会的 35 个 jQuery 小技巧
- 在.NET开发中的单元测试工具之(2)——xUnit.Net
- NSArray基本用法
- Windows服务器远程桌面不能复制粘贴的解决方法
- iOS - NSDateFormatter 日期 和 字符串
- 存储过程和函数
- iOS中MVVM的架构设计
- MySQL重置root用户密码的方法
- 1037 Magic Coupon
- SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property.....
- UnityEditor 用Gizmos画出类似NGUI,UIPanel的矩形框
- 项目管理(一)任务分配
- 遍历二叉树的非递归实现
- 三栏布局(两边固定,中间自适应)
- Python特殊语法:filter、map、reduce、lambda