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

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

 #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. Html5-canvas

    Html5-canvas: 坐标是x向右,逐步增大, y坐标向下增大,原点在画布的左上角.长度单位是一个像素: 像素是一个密度单位,而厘米是长度单位,两者无法比较: Html5的绘图函数: 2.    ...

  2. 更新App版本的流程

    上班一年了还没有自己打包上传过APP,周五下班时项目经理手把手教了我一遍,我大致把流程在这里回顾一下: 1.首先要将svn上的代码拷贝一份到分支上,用终端操作:svn cp https://192.1 ...

  3. 存到cookie里能提高性能吗?

    今天刚刚看了篇微信,大体意思是说g哥之类的网站把很多存session的东西都放cookie里了,可减少服务器的负担种种.然后我就发现我对request到application的记忆有些模糊了,哪些是在 ...

  4. fatal error: 'XCTest/XCTest.h' file not found

    这个报错在几个方面.第一,它导致XCTedt依赖您的应用程序.框架,它只是在Xcode中可用.第二,你使用绝对路径,这并不保证是相同的从Mac Mac(例如,如果你安装了多个版本的Xcode). 这里 ...

  5. 中小网站如何使用谷歌Adsence国际化优势赚钱?

    劲捷电子信息有限公司是一家拿了美国风险投资的互联网公司.他的创办人祁劲松2005年加入AdSense,迄今收获颇丰,为此他还写了一本 <Google AdSense实战宝典>.在祁劲松看来 ...

  6. java并发包:线程池 executorservice

    1.newCachedThreadPool()  -缓存型池子,先查看池中有没有以前建立的线程,如果有,就reuse.如果没有,就建一个新的线程加入池中 -缓存型池子通常用于执行一些生存期很短的异步型 ...

  7. Vector和ArrayList的比较

    今天研究了一下Vector和ArrayList的源码,又加深了对这两个类的理解. List接口下一共实现了三个类:ArrayList,Vector,LinkedList.LinkedList就不多说了 ...

  8. mysql5.7 zip版的配置方法

    下载了最新版的mysql,发现配置后使用net start mysql 服务无法启动,花了点时间找到了解决方案,按照如下步骤就可以了,关键在于创建data文件夹以及mysqld --initializ ...

  9. [windows]部分前缀以及其意义

    前缀                         意义 CS 类风格选项 CW 创建窗口选项 DT 文本绘制选项 IDI 图标的ID号 MB 消息框选项 SND 声音选项 WM 窗口消息 WS 窗 ...

  10. 【Learning Python】【第二章】Python基础类型和基础操作

    基础类型: 整型: py 3.0解决了整数溢出的问题,意味着整型不必考虑32位,64位,有无符号等问题,你写一个1亿亿亿,就是1亿亿亿,不会溢出 a = 10 ** 240 print(a) 执行以上 ...