【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

括号匹配。
栈模拟就好。
多种括号也是一样可以做的。

【代码】

#include <bits/stdc++.h>
using namespace std; const int N = 150; stack <char> sta;
string s; int main() {
#ifdef LOCAL_DEFINE
freopen("F:\\c++source\\rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0),cin.tie(0);
int T;
cin >> T;cin.get();
while (T--) {
while (!sta.empty()) sta.pop();
getline(cin,s);
int n= s.size();
int ok = 1;
for (int i = 0;i < n;i++){
if (s[i]=='(' || s[i] == '[')
sta.push(s[i]);
else if (!sta.empty() && sta.top()=='(' && s[i]==')') sta.pop();
else if (!sta.empty() && sta.top()=='[' && s[i]==']') sta.pop();
else ok = 0;
}
if (!sta.empty()) ok = 0;
if (!ok){
cout << "No" << endl;
}else{
cout << "Yes"<<endl;
}
} return 0;
}

【习题 6-1 UVA-673】Parentheses Balance的更多相关文章

  1. UVa 673 Parentheses Balance -SilverN

    You are given a string consisting of parentheses () and []. A string of this type is said to be corr ...

  2. UVa 673 Parentheses Balance

    一个匹配左右括号的问题 /*UVa 673 Parentheses Balance*/ #include<iostream> #include<algorithm> #incl ...

  3. UVa 673 Parentheses Balance(栈的使用)

     栈 Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu   Description You are ...

  4. UVa 673 Parentheses Balance【栈】

    题意:输入一个包含"()"和"[]"的序列,判断是否合法 用栈来模拟,遇到"(",“[”就入栈,遇到')',']'就取出栈顶元素看是否匹配, ...

  5. UVA 673 Parentheses Balance (栈)

    题意描述: 给出一段只包含()和[]的字符串,判断是否合法,合法输出YES,不合法输出NO 规则: 1.该串为空,则合法 2.若A合法,B合法,则AB合法 3.若A合法,则(A)和[A]均合法 解题思 ...

  6. UVa 673 Parentheses Balance (stack)

    题目描述 : 判断字符串是不是符合正确的表达式形式. 要点 : 考虑字符串为空的时候,用getline输入,每一次判断后如果为No则要清空栈.对称思想. 注意输入格式. 代码: #include &l ...

  7. 【UVA】673 Parentheses Balance(栈处理表达式)

    题目 题目     分析 写了个平淡无奇的栈处理表达式,在WA了5发后发现,我没处理空串,,,,(或者说鲁棒性差?     代码 #include <bits/stdc++.h> usin ...

  8. UVa673 Parentheses Balance

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

  9. UVA 673 (13.08.17)

     Parentheses Balance  You are given a string consisting of parentheses () and []. Astring of this ty ...

  10. Parentheses Balance UVA - 673

    You are given a string consisting of parentheses () and []. A string of this type is said to be corr ...

随机推荐

  1. sublime text 2 licence

    ----- BEGIN LICENSE ----- Andrew Weber Single User License EA7E-855605 813A03DD 5E4AD9E6 6C0EEB94 BC ...

  2. 【Henu ACM Round #13 A】 Hulk

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 模拟. [代码] #include <bits/stdc++.h> using namespace std; int m ...

  3. CCF模拟题 窗口

    窗口 时间限制: 1.0s 内存限制: 256.0MB   问题描述 在某图形操作系统中,有 N 个窗口,每个窗口都是一个两边与坐标轴分别平行的矩形区域.窗口的边界上的点也属于该窗口.窗口之间有层次的 ...

  4. 单向链表 golang

    package main import "fmt" type Object interface {} //节点 type Node struct { data Object nex ...

  5. Nginx模型 & 惊群问题

    这篇写的不错 http://www.cnblogs.com/linguoguo/p/5511293.html Nginx为啥性能高-多进程异步IO模型 1. 对于每个worker进程来说,独立的进程, ...

  6. html的学习思维导图

  7. 前端js中this指向及改变this指向的方法

    js中this指向是一个难点,花了很长时间来整理和学习相关的知识点. 一. this this是JS中的关键字, 它始终指向了一个对象, this是一个指针; 参考博文: JavaScript函数中的 ...

  8. Intellij IDEA中修改项目名称

    如下图红色标识所示: 修改方法见下图:

  9. android图像处理系列之五--给图片添加边框(中)

    前面一篇讲到给图片加边框的方式,只能给图片加一些有规则的边框,如果想加一些比较精美的效果,就有点麻烦了.下面就给出解决这个问题的思路. 思路是:一些比较精美的花边图片我们是很难用代码控制,就目前本人水 ...

  10. 47.__if_not_exists语句

    #include <iostream> using namespace std; template<class T> class myclass { public: T t; ...