UVa 673 平衡的括号
题意:给出包含"()"和"[]"的括号序列,判断是否合法。
用栈来完成,注意空串就行。
#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 平衡的括号的更多相关文章
- UVa 673 Parentheses Balance -SilverN
You are given a string consisting of parentheses () and []. A string of this type is said to be corr ...
- UVa 673 Parentheses Balance
一个匹配左右括号的问题 /*UVa 673 Parentheses Balance*/ #include<iostream> #include<algorithm> #incl ...
- 平衡的括号 (Parentheses Balance UVA - 673)
题目描述: 原题:https://vjudge.net/problem/UVA-673 题目思路: 1.水题 2.栈+模拟 3.坑在有空串 AC代码 #include <iostream> ...
- UVa 673 (括号配对) Parentheses Balance
本来是当做水题来做的,后来发现这道题略坑. 首先输入的字符串可能是空串,所以我用了gets函数,紧接着就被scanf("%d", &n)后面的换行符坑掉了. 于是乎再加一句 ...
- UVa 673 Parentheses Balance(栈的使用)
栈 Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Description You are ...
- UVA 673 (13.08.17)
Parentheses Balance You are given a string consisting of parentheses () and []. Astring of this ty ...
- UVA 673 Parentheses Balance (栈)
题意描述: 给出一段只包含()和[]的字符串,判断是否合法,合法输出YES,不合法输出NO 规则: 1.该串为空,则合法 2.若A合法,B合法,则AB合法 3.若A合法,则(A)和[A]均合法 解题思 ...
- UVa 673 Parentheses Balance【栈】
题意:输入一个包含"()"和"[]"的序列,判断是否合法 用栈来模拟,遇到"(",“[”就入栈,遇到')',']'就取出栈顶元素看是否匹配, ...
- 6-1 平衡的括号 uva673
简单栈题 #include<bits/stdc++.h> using namespace std; int main() { int cas;cin>>cas;getchar( ...
随机推荐
- Individual Project - Word frequency program
1.项目预计用时 -计划学习C#和百度一些用法的时间:5小时 -项目本身打算写两个类,一个是遍历搜索文件夹的,另外一个用来统计单词.计划用时:5小时 2.项目实际用时 学习C#以及正则表达式的用法:3 ...
- python导入cx_Oracle报错的问题!
import cx_Oracle 总是报错:ImportError: DLL load failed: 找不到指定的模块. 或者:ImportError: DLL load failed: %1 不是 ...
- Percona Server 5.6.33-79.0 发布
Percona Server 5.6.33-79.0 发布了,该版本基于 MySQL 5.6.33,包含了所有的 bug 修复,是Percona Server 5.6 系列中的正式版本.该版本主要是修 ...
- 在linux使用make编译ArduPilot for Pixhawk/PX4 ArduPilot 编译环境搭建
Building ArduPilot for Pixhawk/PX4 on Linux with Make 使用Make编译 ArduPilot for Pixhawk 2, Pixhawk and ...
- 生成highcharts报表时对数据没有用= eval('([' + seriesArray+ '])')处理生成数组,而是简单的拼成字符串,结果导致大量的场景出现
<script type="text/javascript"> //异步初始周达成率趋势图信息 function goFinishQuery() { var yearN ...
- 13个JavaScript图表(JS图表)图形绘制插件【转】
现在网络上又有越来越多的免费的(JS 图表)JavaScript图表图形绘制插件.我之前给一家网站做过复杂的图形,我们用的是 highchart.在那段时间,没有很多可供选择的插件.但现在不同了,很容 ...
- C语言复杂声明-void (*signal(int sig, void (*handler)(int)))(int);
问题提出 请分析此声明:void (*signal(int sig, void (*handler)(int)))(int); 求解过程 在对上面的例子作分析之前,我们需要了解C语言的声明优先级,&l ...
- 【搬砖】【Python数据分析】Pycharm中plot绘图不能显示出来
最近在看<Python数据分析>这本书,而自己写代码一直用的是Pycharm,在练习的时候就碰到了plot()绘图不能显示出来的问题.网上翻了一下找到知乎上一篇回答,试了一下好像不行,而且 ...
- jquery.easyui使用详解,和遇到的问题,提供大家在使用的时候少走弯路(二)
上次解释了几个易犯错的地方,当然对于大神们那都是小菜一碟了,今天来说说后台请求数据,分页,返回json数据 废话不多说献上代码 private string QueryList(ArrayList a ...
- Voreen(三) 光线投射参数介绍
本篇介绍光线投射的第二个个制Pass,光线合成的参数,对应于第一篇总的流程介绍中的Processor SingleVolumeRaycaster.可设置的参数如下: 1,Sampling Rate 采 ...