简单栈题

#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. u-boot移植(二)---修改前工作:代码流程分析1

    一.代码执行总体流程图 1.1 代码路径 U-boot.lds (arch\arm\cpu) vectors.S (arch\arm\lib) start.S (arch\arm\cpu\arm920 ...

  2. 进度条QProgressBar

    import sys from PyQt5.QtCore import Qt, QTimer from PyQt5.QtWidgets import QApplication, QWidget, QP ...

  3. QMessageBox消息框

    QMessageBox提供两套接口来实现,一种是static functions(静态方法调用),另外一种 the property-base API(基于属性的API) #需要 from PyQt5 ...

  4. python - 系统交互操作(subprocess)

    本文摘于云游道士 链接:https://www.cnblogs.com/yyds/p/7288916.html 个人简化,便于查询. 命令行指令的执行通常有两个比较关注的结果: 命令执行的状态码--表 ...

  5. ajax大并发问题

    今天在对项目做性能分析时发现,js代码中同时发出的多个异步请求耗时很长,查看服务器处理 时间发现,每个请求的响应都在毫秒级,但是页面请求的响应时间却在1秒左右,百思不得其解,后来仔细测试发现,这个并发 ...

  6. 一个优秀的 ring buffer 或 cycle buffer 的实现代码

    #define CIRCLE_BUFFSIZE 1024 * 1024#define min(x, y) ((x) < (y) ? (x) : (y)) struct cycle_buffer ...

  7. python高级编程读书笔记(一)

    python高级编程读书笔记(一) python 高级编程读书笔记,记录一下基础和高级用法 python2和python3兼容处理 使用sys模块使程序python2和python3兼容 import ...

  8. linux软链接和硬链接的区别

    硬链接:ln 3.txt 4         相当于把源文件复制了一份 软连接:ln -s 3.txt 5 相当于快捷方式 改动源文件4.5同时更新,删除3.txt ,5不存在,4存在的.

  9. sqlserver2008r2实现镜像

    拓扑图 环境 主服务器: 192.168.8.16 winserver2008b 镜像服务器 192.168.11.128 mssql1 见证服务器: 192.168.8.69 server2008c ...

  10. 转载:编译安装Nginx(1.5.1)《深入理解Nginx》(陶辉)

    原文:https://book.2cto.com/201304/19618.html 1.5 configure详解 可以看出,configure命令至关重要,下文将详细介绍如何使用configure ...