题意:给出包含"()"和"[]"的括号序列,判断是否合法。

用栈来完成,注意空串就行。

 #include<iostream>
#include<string>
#include<cstring>
#include<stack>
using namespace std; stack<char> sta;
string s; int solve()
{
char str;
if (s[] == ' ') return ;
else
{
int l = s.length();
for (int i = ; i < l; i++)
{
if (s[i] == '(' || s[i] == '[')
{
sta.push(s[i]);
}
else if (s[i] == ')')
{
str = ' ';
while (str != '(')
{
if (!sta.empty())
{
str = sta.top();
sta.pop();
}
else return ;
}
}
else if (s[i] == ']')
{
str = ' ';
while (str != '[')
{
if (!sta.empty())
{
str = sta.top();
sta.pop();
}
else return ;
}
}
}
}
if(!sta.empty()) return ;
else return ;
} int main()
{
int t;
cin >> t;
getchar();
while (t--)
{
while (!sta.empty()) sta.pop();
getline(cin, s);
int ans=solve();
if (ans) cout << "Yes" << endl;
else cout << "No" << endl;
}
return ;
}

UVa 673 平衡的括号的更多相关文章

  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. 平衡的括号 (Parentheses Balance UVA - 673)

    题目描述: 原题:https://vjudge.net/problem/UVA-673 题目思路: 1.水题 2.栈+模拟 3.坑在有空串 AC代码 #include <iostream> ...

  4. UVa 673 (括号配对) Parentheses Balance

    本来是当做水题来做的,后来发现这道题略坑. 首先输入的字符串可能是空串,所以我用了gets函数,紧接着就被scanf("%d", &n)后面的换行符坑掉了. 于是乎再加一句 ...

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

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

  6. UVA 673 (13.08.17)

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

  7. UVA 673 Parentheses Balance (栈)

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

  8. UVa 673 Parentheses Balance【栈】

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

  9. 6-1 平衡的括号 uva673

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

随机推荐

  1. EasyUI之加载js文件顺序

    在使用EasyUI时,需要引用EasyUI框架的js文件,要注意加载的顺序,jquery.min.js一定要第一个被加载.

  2. java基础之 GC

    Java程序员在编码过程中通常不需要考虑内存问题,JVM经过高度优化的GC机制大部分情况下都能够很好地处理堆(Heap)的清理问题.以至于许多Java程序员认为,我只需要关心何时创建对象,而回收对象, ...

  3. java学习笔记(菜鸟原创)

    搭建Java开发环境使用开发工具开发Myeclipse基础核心:JAVASEEEME面向对象 API JVM.JAVAEE是指java enterprise edition,java企业版,多用于企业 ...

  4. 关闭键盘导致tableView:didSelectRowAtIndexPath:失效解决办法

    今天公司的小兄弟问了tableView:didSelectRowAtIndexPath:不能执行的问题. 从经验看觉得可能是控制器没有成为tableView的代理所致.但代码中已经添加了代码 _tab ...

  5. 如何在静态博客hexo中只显示摘要信息

    默认情况下hexo博客(如本站)的首页显示的是完整的文章 – 而文章比较长的时候这无疑会带来诸多不遍. 那怎么样才能只显示个摘要呢? 方法说白了,其实很简单 – 只要加入一个<!-- more ...

  6. Ubuntu下libpcap安装

    1.首先按下面的博客教程下载和安装四个软件包: 点击打开链接 2.这四个软件都安装好之后按下面教程新建Makefile文件和test.c文件: 点击打开链接 Makefie: all: test.c ...

  7. css中文乱码与替换字符

    有时候,我们的css样式表中字体乱码,很诧异.百度谷歌是两个老师,有时jquery博客还上淘宝,那边有现成的代码,看看,发现里面定义全局字体是这样的font:12px/1.5 tahoma,arial ...

  8. PHP的几个常用函数的使用总结

    1.date函数:不得不说,PHP的date函数已经基本很完备了,如果你不去读PHP的手册的话,你不会发现对日期做了那么多的支持. time()  获取当前的时间戳 data() 获取自己想要的时间格 ...

  9. 安装ant问题

    1  设置path, 在windwos 7下要重启 2  重启后,cmd----ant -version  Unable to locate tools.jar. Expected to find i ...

  10. ASP.NET输出JSON格式数据

    找到一个方法,虽然返回的不是json,但是数据格式是可以的 ArrayList eventList = new ArrayList(); ; i < ;i++ ) { Hashtable ht ...