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( ...
随机推荐
- CIB Training Scripts For TPC-H Benchmark
http://52.11.56.155:7180/http://52.11.56.155:8888/ impala-shell -i 172.31.25.244 sudo -u hdfs hdfs d ...
- Oracle Merge into 详细介绍
Oracle Merge into 详细介绍 /*Merge into 详细介绍MERGE语句是Oracle9i新增的语法,用来合并UPDATE和INSERT语句.通过MERGE语句,根据一张表或子查 ...
- RN的像素及布局
转自:http://www.cocoachina.com/ios/20150420/11608.html 宽度单位和像素密度 react的宽度不支持百分比,设置宽度时不需要带单位 {width: 10 ...
- VM virtuaBox异常关机启动不了的解决方案
事件回放 我的物理机是win7,上面装了一个VM virtualBox,用来装Centos,有天物理机非正常关闭,导致VM virtuaBox异常关机启动不了,如下: 确实找不到这个vm_liang. ...
- sqlserver 存储过程分页管理
-- =============================================-- Author: <Author:刘畅>-- Create date: <Cre ...
- 【python】操作excel——xlrd xlwt xlutils
from xlutils.copy import copy import xlrd # import xlutils #打开已存在的excel rb=xlrd.open_workbook('D:\\1 ...
- WebSocket通信协议
var ws = new WebSocket("ws://echo.websocket.org"); ws.onopen = function(){ws.send("Te ...
- mybatis配置文件查询参数的传递
通常来说,参数传递可以使用#与$进行编写,但是使用#的效率更高,使用$方式,查看日志更方便些,尤其是当执行的sql语句非常麻烦的时候. 1) 接口 形式 以下方式 [传递参数是一个实体] public ...
- Samba - 文件共享服务器的搭建和配置
下载与安装: deb包安装 官方deb包下载:http://packages.ubuntu.com/ 命令安装dpkg –i xxxx.deb (安装不成功留意日志安装依赖包) apt安装 apt-g ...
- ajax登陆提示
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Con ...