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( ...
随机推荐
- 原生js实现放大镜效果
今天做任务的时候,有一个任务就是让实现电商网站常用的放大镜效果,类似于这样的效果,之前并没有做过这种放大镜效果,刚开始的思路是对图片进行裁剪,但是后来发现实在是难以实现,于是求助了万能的谷歌,发现一个 ...
- hypermesh2flac3d
hypermesh2ansys2flac3d 目的: 将hypermesh中划分的网格输出到flac3d中.过程是hypermesh12.0-ansys13.0-flac3d3.0. 视频教程详见:h ...
- SQLServer - 约束
一.约束的分类 在SQLServer中,有3种不同类型的约束. 1.实体约束 实体约束是关于行的,比如某一行出现的值就不允许出现在其他行,例如主键. 2.域约束 域约束是关于列的,对于所有行,某一列有 ...
- thymeleaf常用标签
1. th:checked ,th:selected标签<input type="radio" value="M" name="gender&q ...
- C# 使用 fckeditor 上传文件中文名乱码的问题---转
提到中文乱码,首先肯定是由于编码问题引起的所以就从编码转换入手,尝试了将UTF-8转换为GB2312,但发现无论如何没有办法转成功 看到很多文章说修改配置文件 <globalization re ...
- Empty 和空字符串区别
如果 var 是非空或非零的值,则 empty() 返回 FALSE. 换句话说,"".0."0".NULL.FALSE.array().var $var; 以 ...
- ArcMap常用VBA
--点坐标X VBA部分: Dim pGeo As IGeometry Set pGeo = [Shape] Dim pPoint As IPoint Set pPoint = pGeo 赋值部分: ...
- label标签
- opnet学习过程
学习opnet有一段时间了,走了 不少弯路,现在,想总结一下,推荐给大家一个比较好的学习过程. 因为英语不太好,所以在开始学opnet时用了很多心思去找中文资料,比如说,一些文档.书.视频等.看文档和 ...
- windows10和ubuntu16.04双系统下时间不对的问题 ZT
最近装了windows10和ubuntu16.04双系统,仍然出现了喜闻乐见的老问题,装完后,在windows下时区不对,之前的老办法是: sudo gedit /etc/default/rcS ut ...