简单栈题

#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++中路径的处理方法(string)

    string 类提供字符串处理函数,利用这些函数,程序员可以在字符串内查找字符,提取连续字符序列(称为子串),以及在字符串中删除和添加.我们将介绍一些主要函数. 1.函数find_first_of() ...

  2. Python杀死windows进程

    import os import pandas as pd """ TCP 192.168.1.155:63758 129.211.126.69:4730 ESTABLI ...

  3. tidb 架构~tidb 理论学习(1)

    一 简介:介绍新型NEW SQL数据库tidb 二 目的: tidb出现的目的,就是代替mysql+中间件,实现横向水平扩展 三 核心理论观点 1 MySQL 是单机数据库,只能通过 XA 来满足跨数 ...

  4. 使用css将图像居中

    默认情况下,图像属于内联元素.这意味着它们与周围的文本一起流动.为使图像居中,我们应该将其转换成块级元素,通过将display属性的值设置为block就可以完成转换. <html> < ...

  5. Django开发笔记五

    Django开发笔记一 Django开发笔记二 Django开发笔记三 Django开发笔记四 Django开发笔记五 Django开发笔记六 1.页面继承 定义base.html: <!DOC ...

  6. Jetson tk1 刷机后要做的几件事

    参考简书文章: http://www.jianshu.com/p/997ede860d74 1. 查看Jetson TK1 L4T版本 head -n 1 /etc/nv_tegra_release ...

  7. jquery开发自定义的插件总结

    1.第一种方式,有元素的插件 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "htt ...

  8. 【转】Shell编程基础篇-上

    [转]Shell编程基础篇-上 1.1 前言 1.1.1 为什么学Shell Shell脚本语言是实现Linux/UNIX系统管理及自动化运维所必备的重要工具, Linux/UNIX系统的底层及基础应 ...

  9. Django 利用管理器实现文章归档

    Django管理器:class Manager 管理器是Django的模型进行数据库查询的接口,Django应用的每个模型都拥有至少一个管理器.默认情况下,Django为每个模型类添加一个名为obje ...

  10. dubbo系列二、dubbo+zookeeper+dubboadmin分布式服务框架搭建(windows平台)

    一.zookeeper配置中心安装 1.下载安装包,zookeeper-3.4.6.tar.gz 2.解压安装包,修改配置文件 参考zookeeper-3.4.6/conf/zoo_sample.cf ...