简单栈题

#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. SQL——sql年龄段查询

    select * from 表 p where p.gender <> '男' ) ) select * ) ) 查询出所有年龄在15~49岁的非男性的信息

  2. 日期与时间控件QDate, QTime, QDateTime

    QDate类用于处理公历日期.QTime类用于处理时间.QDateTime类将QDate对象和QTime对象整合为一个对象 QDate: from PyQt5.QtCore import QDate, ...

  3. 基于json文件实现的gearman任务自动重启

    一:在gearman任务失败后,调用task_failed def task_failed(task, *args): info = '\n'.join(args) datetime = local_ ...

  4. php 利用root 权限执行shell脚本

    http://blog.csdn.net/lxwxiao/article/details/8513355 也可以指定某个shell文件不需要密码 www-data ALL=(ALL) NOPASSWD ...

  5. 快速创建SpringBoot2.x应用之工具类自动创建web应用、SpringBoot2.x的依赖默认Maven版本

    快速创建SpringBoot2.x应用之工具类自动创建web应用简介:使用构建工具自动生成项目基本架构 1.工具自动创建:http://start.spring.io/ 2.访问地址:http://l ...

  6. Java对象与JSON互相转换jsonlib以及手动创建JSON对象与数组——(二)

    首先声明一下,jsonlib转换与GSON相比太差劲了,操作不是一般的繁琐.GSON可以直接转换成各种集合与对象类型.强烈推荐使用GSON.而且GSON一个方法就可以解决,jsonlib转来转去太繁琐 ...

  7. linux 网卡

    查看网卡UUID:nmcli con show    或    nmcli con list 查看网卡mac地址:nmcli dev show    或    nmcli dev list 注:sho ...

  8. SpringBoot三种配置Dubbo的方式

    *必须首先导入dubbo-starter (1).使用SpringBoot配置文件(application.properties或application.yml) dubbo.application. ...

  9. 理解 Linux 配置文件【转】

    转自:http://www.ibm.com/developerworks/cn/linux/management/configuration/ 分类和使用 本文说明了 Linux 系统的配置文件,在多 ...

  10. Linux内核源码分析--内核启动之(5)Image内核启动(rest_init函数)(Linux-3.0 ARMv7)【转】

    前面粗略分析start_kernel函数,此函数中基本上是对内存管理和各子系统的数据结构初始化.在内核初始化函数start_kernel执行到最后,就是调用rest_init函数,这个函数的主要使命就 ...