一个匹配左右括号的问题

/*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的更多相关文章

  1. UVa 673 Parentheses Balance -SilverN

    You are given a string consisting of parentheses () and []. A string of this type is said to be corr ...

  2. UVa 673 Parentheses Balance(栈的使用)

     栈 Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu   Description You are ...

  3. UVa 673 Parentheses Balance【栈】

    题意:输入一个包含"()"和"[]"的序列,判断是否合法 用栈来模拟,遇到"(",“[”就入栈,遇到')',']'就取出栈顶元素看是否匹配, ...

  4. UVA 673 Parentheses Balance (栈)

    题意描述: 给出一段只包含()和[]的字符串,判断是否合法,合法输出YES,不合法输出NO 规则: 1.该串为空,则合法 2.若A合法,B合法,则AB合法 3.若A合法,则(A)和[A]均合法 解题思 ...

  5. UVa 673 Parentheses Balance (stack)

    题目描述 : 判断字符串是不是符合正确的表达式形式. 要点 : 考虑字符串为空的时候,用getline输入,每一次判断后如果为No则要清空栈.对称思想. 注意输入格式. 代码: #include &l ...

  6. 【UVA】673 Parentheses Balance(栈处理表达式)

    题目 题目     分析 写了个平淡无奇的栈处理表达式,在WA了5发后发现,我没处理空串,,,,(或者说鲁棒性差?     代码 #include <bits/stdc++.h> usin ...

  7. UVa673 Parentheses Balance

    // UVa673 Parentheses Balance // 题意:输入一个包含()和[]的括号序列,判断是否合法. // 具体递归定义如下:1.空串合法:2.如果A和B都合法,则AB合法:3.如 ...

  8. UVA 673 (13.08.17)

     Parentheses Balance  You are given a string consisting of parentheses () and []. Astring of this ty ...

  9. Parentheses Balance UVA - 673

    You are given a string consisting of parentheses () and []. A string of this type is said to be corr ...

随机推荐

  1. git push ERROR: missing Change-Id in commit message footer

    今天上传代码时候报告错误:$ git push origin HEAD:refs/for/branch*Counting objects: 7, done.Delta compression usin ...

  2. Linux 信号详解六(可靠信号与不可靠信号)

    #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h&g ...

  3. [转]C#压缩打包文件

    /// <summary> /// 压缩和解压文件 /// </summary> public class ZipClass { /// <summary> /// ...

  4. Oracle Coherence应用部署到Jboss EAP 6.x 时 NoClassDefFoundError: sun/rmi/server/MarshalOutputStream 的解决办法

    今天将一个web应用从weblogic 10.3迁移到jboss EAP 6.3上,该应用使用oracle coherence做为缓存,部署上去后,启动时一直报如下错误:     at java.ut ...

  5. 国内优秀Android学习资源

    技术博客 应用开发 博主 博客 备注 任玉刚 CSDN博客 深入Android应用开发,深度与广度兼顾 郭霖 CSDN博客 内容实用,行文流畅,高人气博主 夏安明 CSDN博客   张鸿洋 CSDN博 ...

  6. vbs外部调用

    一.QTP调用外部VBS的方法 加到QTP的Resource中 在QTP菜单中设置, 菜单FileàSettingsàResource,将要加载的VB脚本添加进来. 举例: 步骤1:在D盘下新建一个V ...

  7. 继续node爬虫 — 百行代码自制自动AC机器人日解千题攻占HDOJ

    前言 不说话,先猛戳 Ranklist 看我排名. 这是用 node 自动刷题大概半天的 "战绩",本文就来为大家简单讲解下如何用 node 做一个 "自动AC机&quo ...

  8. Web性能优化-合并js与css,减少请求

    Web性能优化已经是老生常谈的话题了, 不过笔者也一直没放在心上,主要的原因还是项目的用户量以及页面中的js,css文件就那几个,感觉没什么优化的.人总要进步的嘛,最近在被angularjs吸引着,也 ...

  9. DbEntry在Vs2012里的配置

    dbentry官方的版本还不支持vs2012,要再vs2012中使用,必须做下调整 1:新建类库项目,然后添加dbentry 的dll引用. 2:在建好的类库项目中.csproj 新添加了类库项目后, ...

  10. SQL Server使用游标或临时表遍历数据

    方法一:使用游标(此方法适用所有情况,对标结构没有特殊要求.) declare @ProductName nvarchar() declare pcurr cursor for select Prod ...