//P176 test 6-1
#include<cstdio>
#include<stack>
#include<string>
#include<iostream>
using namespace std;

int main(){
    freopen("p.txt","r",stdin);
    freopen("pout.txt","w",stdout);
    string s;
    while( cin >> s){
        stack<char> t;
        if(s.empty()){
            printf("YES\n");
            continue;
        }
        ; i < s.size();i++){
            switch(s[i]){
                case '[':t.push(s[i]);break;
                case '(':t.push(s[i]);break;
                case ']':if(t.top() == '[')t.pop();else t.push(s[i]);break;
                case ')':if(t.top() == '(')t.pop();else t.push(s[i]);break;
                default :break;
            }
        }
        if(t.empty())printf("YES\n");
        else printf("NO\n");
    }
}

P176 test 6-1 UVa673的更多相关文章

  1. UVa673 Parentheses Balance

    // UVa673 Parentheses Balance // 题意:输入一个包含()和[]的括号序列,判断是否合法. // 具体递归定义如下:1.空串合法:2.如果A和B都合法,则AB合法:3.如 ...

  2. [刷题]算法竞赛入门经典(第2版) 6-1/UVa673 6-2/UVa712 6-3/UVa536

    这三题比较简单,只放代码了. 题目:6-1 UVa673 - Parentheses Balance //UVa673 - Parentheses Balance //Accepted 0.000s ...

  3. uva673 - Parentheses Balance(栈)

    题意:1.空串合法.2.若A和B合法,则AB合法.3.若A合法,则(A)和[A]合法. 思路:遍历串,遇到(或[,则压入队列,若遇到),判断:若栈空,则不合法:若栈顶元素不是(,也不合法.]同理.因为 ...

  4. UVA-673 括号匹配--栈

    如果是一个合法的序列,每对配对的括号的两个字符('(' 和 ')' 或者 '[' 和 ']')一定是相邻的,每次判断下该字符是否有配对即可. 如果配对,将左括号出栈即可.特别注意:空格也是合法的. A ...

  5. 6-1 平衡的括号 uva673

    简单栈题 #include<bits/stdc++.h> using namespace std; int main() { int cas;cin>>cas;getchar( ...

  6. UVA-673 Parentheses Balance(栈)

    题目大意:给一个括号串,看是否匹配. 题目分析:一开始用区间DP写的,超时了... 注意:空串合法. 代码如下: # include<iostream> # include<cstd ...

  7. STL应用——UVA673(堆栈)

    分析:栈的应用,遇到右括号便弹出栈顶元素,看是否与右括号相互匹配,其余情况压入栈. 注意:本题有坑,空串空串,为此我跪了数次 #include<iostream> #include< ...

  8. 【习题 6-1 UVA-673】Parentheses Balance

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 括号匹配. 栈模拟就好. 多种括号也是一样可以做的. [代码] #include <bits/stdc++.h> usi ...

  9. C++语法-指针 (1)

    <C++程序设计> 谭浩强  清华大学出版社 2016-08-03 1.P167 一般的C++编译系统为每个指针变量分配4个字节的存储单元,用来存放变量的地址. 2.P169 .cpp文件 ...

随机推荐

  1. JQuery中 json 和字符串直接相互转换

    json字符串转json对象:jQuery.parseJSON(jsonStr); json对象转json字符串:JSON.stringify(jsonObj);   IE中可能对unicode使用“ ...

  2. iOS UICollectionView高级用法(长按自由移动cell)-新

    [reference]http://www.jianshu.com/p/31d07bf32d62 iOS 9之后: 示例如下 效果 前言: 看完你可以学到哪些呢? 就是文章标题那么多, 只有那么多. ...

  3. javascript中的__proto__和prototype

    一.2个参考网址: http://icekiller110.iteye.com/blog/1566768 http://www.cnblogs.com/snandy/archive/2012/09/0 ...

  4. 安卓 SQLite error:SQLite database locked exception while compling : PRAGMA journal_mode .....

    项目中频繁的切换Tab键,会频繁地从数据库读取数据,这是报出这样的错误: 解决方法是在国外的某论坛找到的 : 在插入数据的时候,首先: SQLiteDatabase db = SQLiteDataba ...

  5. delphi的ArrayList

    本文转载自Top.hand<delphi的ArrayList>   delphi可以用Classes.TList类来实现ArrayList功能.注意:add()方法存入的类型是TPoint ...

  6. iOS 开源库 之 AFNetWorking 2.x

    1. 网络请求的基本知识 2. Get/Post 请求的使用 3. 文件(图片)上传 4. 断点下载 5. 其它使用细节 6. 设计优良的地方

  7. codeforces 755D. PolandBall and Polygon

    D. PolandBall and Polygon time limit per test 4 seconds memory limit per test 256 megabytes input st ...

  8. HDU1548:A strange lift(Dijkstra或BFS)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1548 题意:电梯每层有一个数,例如第n层有个数k, 那么这一层只能上k层或下k层,但是不能低于一层或高 ...

  9. javascript设计模式之解释器模式详解

    http://www.jb51.net/article/50680.htm 神马是“解释器模式”? 先翻开<GOF>看看Definition:给定一个语言,定义它的文法的一种表示,并定义一 ...

  10. multipathd dead but pid file exists

    构建RAC环境时出现的错误 百度半天未找到解决方案,Google了一下,终于找到可行方案 Solution:- yum update device-mapper glibc -y [root@HE2 ...