简单栈题

#include<bits/stdc++.h>
using namespace std; int main()
{ int cas;cin>>cas;getchar();
string ss;
while(cas--)
{
stack<char>s;char ch;
getline(cin,ss);int ok=;
for(int i=;i<ss.size();i++)
{
// printf("%c ",ss[i]);
if(ss[i]=='('||ss[i]=='[')s.push(ss[i]);
else if(ss[i]==')'&&!s.empty())
{
ch=s.top();s.pop();
if(ch!='('){ok=;break;}
}
else if(ss[i]==']'&&!s.empty())
{
ch=s.top();s.pop();
if(ch!='['){ok=;break;}
}
else if(ss[i]==' ')continue;
else {ok=;break;} }
if(!s.empty())ok=;
printf("%s\n",ok?"Yes":"No"); }
}

6-1 平衡的括号 uva673的更多相关文章

  1. UVa 673 平衡的括号

    题意:给出包含"()"和"[]"的括号序列,判断是否合法. 用栈来完成,注意空串就行. #include<iostream> #include< ...

  2. 平衡的括号 (Parentheses Balance UVA - 673)

    题目描述: 原题:https://vjudge.net/problem/UVA-673 题目思路: 1.水题 2.栈+模拟 3.坑在有空串 AC代码 #include <iostream> ...

  3. Parentheses Balance (括号平衡)---栈

    题目链接:https://vjudge.net/contest/171027#problem/E Yes的输出条件: 1. 空字符串 2.形如()[]; 3.形如([])或者[()] 分析: 1.设置 ...

  4. Leetcode 856. Score of Parentheses 括号得分(栈)

    Leetcode 856. Score of Parentheses 括号得分(栈) 题目描述 字符串S包含平衡的括号(即左右必定匹配),使用下面的规则计算得分 () 得1分 AB 得A+B的分,比如 ...

  5. 2016年湖南省第十二届大学生计算机程序设计竞赛---Parenthesis(线段树求区间最值)

    原题链接 http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1809 Description Bobo has a balanced parenthes ...

  6. CSU 1809 Parenthesis(线段树+前缀和)

    Parenthesis Problem Description: Bobo has a balanced parenthesis sequence P=p1 p2-pn of length n and ...

  7. Codeforces Gym 100803G Flipping Parentheses 线段树+二分

    Flipping Parentheses 题目连接: http://codeforces.com/gym/100803/attachments Description A string consist ...

  8. JavaScript: 世界上最被误解的语言|Douglas Crockford

    JavaScript: 世界上最被误解的语言 JavaScript: The Wrrrld's Most Misunderstood Programming Language Douglas Croc ...

  9. CSU 1809 - Parenthesis - [前缀和+维护区间最小值][线段树/RMQ]

    题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1809 Bobo has a balanced parenthesis sequenc ...

随机推荐

  1. C# 与 SQL Server 的数据类型对应关系

    (一)C#与SQL Server 2005(或以下版本): C# C#取值 SQL Server SQL Server取值 System.DateTime samlltime System.Objec ...

  2. 20155228 2016-2017-2 《Java程序设计》第7周学习总结

    20155228 2016-2017-2 <Java程序设计>第7周学习总结 教材学习内容总结 Lambda 方法参考的特性,在重用现有的API上扮演了重要的角色.重用现有方法操作,可以避 ...

  3. 绘图QPainter-画笔

    绘图要在paintEvent()方法中实现.在QPainter对象的begin()与end()方法间编写绘图代码.它会在控件或其他图形设备上进行低级的图形绘制 画笔样式Penstyle Qt.Nope ...

  4. 第18月第19天 masonry等分 uilabel sizetofit

    1.masonry等分 mas_distributeViewsAlongAxis MASAxisTypeHorizontal 2.uilabel sizetofit +(CGSize)labSizeW ...

  5. 出现fonts/fontawesome-webfont.woff?v=4.5.0 net::ERR_ABORTED

    虽然网页正常显示和运行,但是有2个字体文件出现404错误. 原因:服务器没有配置MIME类型而已. 1. 在IIS网站中,找打网站对应的MIME类型,双击. 2.能看到此网站对应的MIME类型,点击右 ...

  6. mysql 架构 ~ PXC5.7.20安装尝试

    简介:今天来尝试下 pxc 5.7.20安装1 环境安装   yum install -y git scons gcc gcc-c++ openssl check cmake bison boost- ...

  7. mysql 查询优化案例汇总

    一 简介:此文章为经历过的sql案例集合和相关思路 二 案例1: 现象: 测试环境出现select语句,join2张表多次join,explain结果如下 出现 using where,using j ...

  8. Java 集合系列0、概述

    概述: Collection 框架中 从最上层的核心主干可以看到:Iterator.Collection.Map 三个接口(拓展思考1)1.Collection 接口:主要包括了集合中的一些常用操作, ...

  9. MySQL— 基础

    目录 一.MySQL概述 二.下载安装 三.数据库操作 四.数据表操作 五.表内容操作 一.MySQL概述 MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,目前属于 Oracl ...

  10. linux kernel的cmdline参数解析原理分析【转】

    转自:https://blog.csdn.net/skyflying2012/article/details/41142801 版权声明:本文为博主kerneler辛苦原创,未经允许不得转载. htt ...