UVa 673 Parentheses Balance
一个匹配左右括号的问题
/*UVa 673 Parentheses Balance*/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<stack>
using namespace std;
char c[500];
int n;
int pd(char q,char e){
if(q=='(' && e==')')return 1;
if(q=='[' && e==']')return 1;
return 0;
}
int main(){
scanf("%d\n",&n);
while(n--){
gets(c);
if(strcmp(c,"\n")==0){
printf("Yes");
continue;
}
int flag=0;
stack<char>st;
int L=strlen(c);
for(int i=0;i<L;i++){
if(c[i]=='(' || c[i]=='[') st.push(c[i]);
else{
if(st.empty()){
flag=1;
break;
}
if(pd(st.top(),c[i])==1) st.pop();
else{
flag=1;
break;
}
}
}
if(flag==1 || !st.empty())printf("No\n");
else printf("Yes\n");
}
return 0;
}
UVa 673 Parentheses Balance的更多相关文章
- 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(栈的使用)
栈 Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Description You are ...
- UVa 673 Parentheses Balance【栈】
题意:输入一个包含"()"和"[]"的序列,判断是否合法 用栈来模拟,遇到"(",“[”就入栈,遇到')',']'就取出栈顶元素看是否匹配, ...
- UVA 673 Parentheses Balance (栈)
题意描述: 给出一段只包含()和[]的字符串,判断是否合法,合法输出YES,不合法输出NO 规则: 1.该串为空,则合法 2.若A合法,B合法,则AB合法 3.若A合法,则(A)和[A]均合法 解题思 ...
- UVa 673 Parentheses Balance (stack)
题目描述 : 判断字符串是不是符合正确的表达式形式. 要点 : 考虑字符串为空的时候,用getline输入,每一次判断后如果为No则要清空栈.对称思想. 注意输入格式. 代码: #include &l ...
- 【UVA】673 Parentheses Balance(栈处理表达式)
题目 题目 分析 写了个平淡无奇的栈处理表达式,在WA了5发后发现,我没处理空串,,,,(或者说鲁棒性差? 代码 #include <bits/stdc++.h> usin ...
- 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 ...
- Parentheses Balance UVA - 673
You are given a string consisting of parentheses () and []. A string of this type is said to be corr ...
随机推荐
- Oracle Coherence应用部署到Jboss EAP 6.x 时 NoClassDefFoundError: sun/rmi/server/MarshalOutputStream 的解决办法
今天将一个web应用从weblogic 10.3迁移到jboss EAP 6.3上,该应用使用oracle coherence做为缓存,部署上去后,启动时一直报如下错误: at java.ut ...
- Theano2.1.1-基础知识之准备工作
来源:http://deeplearning.net/software/theano/tutorial/index.html#tutorial 这里介绍的是使用theano的一些基础知识,虽然thea ...
- Web Api 2 接口API文档美化
使用用第三方提供的swgger ui 帮助提高 web api 接口列表的阅读性,并且可以在页面中测试服务接口. 运行程序如下: 注意:在IE中必须输入红色部分. 并且可以对方法进行测试. 在开发we ...
- jquery 选择器大全
jquery 选择器大体上可分为4 类: 1.基本选择器 2.层次选择器 3.过滤选择器 4.表单选择器 其中过滤选择器可以分为: 1.简单过滤选择器 2.内容过滤选择器 3.可见性过滤选择器 4.属 ...
- codevs 4543 treap 模板
type rec=record lc,rc,v,rnd,size,w,fa:longint; end; var n,root,tot,ans,opt,x,i,po:longint; tr:array[ ...
- 使用 Socket 通信实现 FTP 客户端程序(来自IBM)
FTP 客户端如 FlashFXP,File Zilla 被广泛应用,原理上都是用底层的 Socket 来实现.FTP 客户端与服务器端进行数据交换必须建立两个套接字,一个作为命令通道,一个作为数据通 ...
- 如果在敲代码的时候eclipse不弹出提示,怎么办?
非常弱智的操作,我们曾经在输入System.out.println("content");的时候,当我们输入了"."之后,在输入错误,此时我们再回退至" ...
- linux定时任务生产java服务无法执行问题案例
我写了一个重启resin的脚本,由于业务原因,需要定时在某一个时间重启下resin服务器 于是就在crontab里配置了如下内容: * * - root /usr/local/bin/resin_re ...
- MyBatis学习--mybatis开发dao的方法
简介 使用Mybatis开发Dao,通常有两个方法,即原始Dao开发方法和Mapper接口开发方法. 主要概念介绍: MyBatis中进行Dao开发时候有几个重要的类,它们是SqlSessionFac ...
- 'hibernate.dialect' must be set when no Connection avalable’
一个错误'hibernate.dialect' must be set when no Connection avalable ‘ 网上也有不少人遇到这种问题,看上去好像是跟Hibernate的方言有 ...