UVA514Rails
来源:互联网 发布:红色报刊档案数据库 编辑:程序博客网 时间:2024/06/11 03:20
//UVA514#include<cstdio>#include<cstdlib>#include<stack>using namespace std;const int MAXN = 1000 + 10; int main() {int n = 0, tmp;int count = 0;while(scanf("%d", &n) && n) {if(count++) printf("\n");while(1) { int out[MAXN] = {0}; int in = 1; scanf("%d", &out[1]); if(out[1] == 0) break; for(int i = 2; i <= n; i++) scanf("%d", &out[i]); int index = 1; stack<int> s; int ok = 1; while(index <= n) { if(out[index] == in) { index++; in++;//在之前的输入输出数据合法性已经检验完毕时,当前的输入数据和输出数据相等,说明单个输入值入栈后直接出栈了 } else if(!s.empty() && s.top() == out[index]) { s.pop(); index++;//栈中的数据该出列的了 } else if(in <= n) { s.push(in++);//当前输入数据还没有到直接出去的时候,那么除了不合法外,只能是应先入栈 } else { ok = 0; break; } //printf("index = %d, in = %d*\n", index, in); } if(ok) printf("Yes\n"); else printf("No\n"); //scanf("%d", &n); /*if(!n) { printf("\n"); break; }*/ }}printf("\n");return 0;} /*51 2 3 4 55 4 1 2 3066 5 4 3 2 100*/
阅读全文
0 0
- UVA514Rails
- 为什么Java中字符串被设计成不可变的?
- CentOS 6.7构建 OpenResty(Nginx)+PHP 7(php-fpm)+MySQL5.7 运行环境
- 面向对象-单例设计模式
- java中常用名词
- git命令大全(非常齐全)
- UVA514Rails
- JAVA日期格式化工具【L】
- Red and Black
- NYOJ-105-九的余数(数论)
- 深度学习21天实战实战caffe学习笔记<3>
- JSP(一)--部署web应用/JSP运行原理/在 myeclipse环境中集成tomcat/脚本元素/指令元素/动作元素/动态包含/转发/传递参数
- Java中的创建多线程的方法
- Linux---lseek函数
- Vue.js UI框架比较