UVA-673 Parentheses Balance(栈)
题目大意:给一个括号串,看是否匹配。
题目分析:一开始用区间DP写的,超时了。。。
注意:空串合法。
代码如下:
# include<iostream>
# include<cstdio>
# include<stack>
# include<cstring>
# include<algorithm>
using namespace std; char p[130];
stack<char>s; bool judge()
{
int len=strlen(p);
if(len==0)
return true; while(!s.empty())
s.pop();
for(int i=0;i<len;++i){
if(p[i]=='('||p[i]=='[')
s.push(p[i]);
else{
if(s.empty())
return false;
char c=s.top();
if(c=='('&&p[i]!=')')
return false;
if(c=='['&&p[i]!=']')
return false;
s.pop();
}
}
return s.empty();
} int main()
{
int T;
scanf("%d",&T);
getchar();
while(T--)
{
gets(p);
if(judge())
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
UVA-673 Parentheses Balance(栈)的更多相关文章
- UVA 673 Parentheses Balance (栈)
题意描述: 给出一段只包含()和[]的字符串,判断是否合法,合法输出YES,不合法输出NO 规则: 1.该串为空,则合法 2.若A合法,B合法,则AB合法 3.若A合法,则(A)和[A]均合法 解题思 ...
- 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 ...
- UVa 673 Parentheses Balance(栈的使用)
栈 Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Description You are ...
- UVa 673 Parentheses Balance【栈】
题意:输入一个包含"()"和"[]"的序列,判断是否合法 用栈来模拟,遇到"(",“[”就入栈,遇到')',']'就取出栈顶元素看是否匹配, ...
- UVa 673 Parentheses Balance (stack)
题目描述 : 判断字符串是不是符合正确的表达式形式. 要点 : 考虑字符串为空的时候,用getline输入,每一次判断后如果为No则要清空栈.对称思想. 注意输入格式. 代码: #include &l ...
- 【UVA】673 Parentheses Balance(栈处理表达式)
题目 题目 分析 写了个平淡无奇的栈处理表达式,在WA了5发后发现,我没处理空串,,,,(或者说鲁棒性差? 代码 #include <bits/stdc++.h> usin ...
- uva673 - Parentheses Balance(栈)
题意:1.空串合法.2.若A和B合法,则AB合法.3.若A合法,则(A)和[A]合法. 思路:遍历串,遇到(或[,则压入队列,若遇到),判断:若栈空,则不合法:若栈顶元素不是(,也不合法.]同理.因为 ...
- UVa673 Parentheses Balance
// UVa673 Parentheses Balance // 题意:输入一个包含()和[]的括号序列,判断是否合法. // 具体递归定义如下:1.空串合法:2.如果A和B都合法,则AB合法:3.如 ...
- UVA 673 (13.08.17)
Parentheses Balance You are given a string consisting of parentheses () and []. Astring of this ty ...
随机推荐
- 南京网络赛I-Skr【回文树模板】
19.32% 1000ms 256000K A number is skr, if and only if it's unchanged after being reversed. For examp ...
- 一个不需要Log4Net的写日志的简单方法
有些项目写日志时会选择大名鼎鼎的Log4Net.而在我们使用它时,总会出现一些诸如版本不匹配而造成的写日志失败的情况,还要改web.config,还要改AssemblyInfo.而且,它的失败,并不是 ...
- spring boot 打包方式 spring boot 整合mybaits REST services
<build> <sourceDirectory>src/main/java</sourceDirectory> <plugins> <plugi ...
- ping 10.13.5.233
3. 环境 URL选择器 tableView ping 10.13.5.233
- numpy基本方法总结 --good
https://www.cnblogs.com/xinchrome/p/5043480.html 一.数组方法 创建数组:arange()创建一维数组:array()创建一维或多维数组,其参数是类似于 ...
- OC最基础的系统转场动画
SystemAnimationViewController *system = [SystemAnimationViewController new]; CATransition *animation ...
- apache ab test使用 单独安装ab和htpasswd
apache ab test使用 apache ab test使用 单独安装ab和htpasswd 转载自: http://www.cnblogs.com/super-d2/p/3831155.htm ...
- 一个兼职DBA的数据库运维经验 小米科技 xx@xiaomi.com 2011
一个兼职DBA的数据库运维经验 小米科技 xx@xiaomi.com 2011 内存扩容 16G->64G ,调大bp后,凌晨说监控物理内存有余量情况下,开吃swap,内存泄露措施1 定时 ...
- Spring Boot+CXF搭建WebService
Spring Boot WebService开发 需要依赖Maven的Pom清单 <?xml version="1.0" encoding="UTF-8" ...
- 认识与设计Serverless(二)
一.设计Serverless的功能模块 第一节讲了Serverless一些概念与特性,废话居多,概念的东西了解过后要有设计与构思,才能学到精髓,一个Serverless平台的形成,涉及到很多模块的架构 ...