6-1 平衡的括号 uva673
简单栈题
#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的更多相关文章
- UVa 673 平衡的括号
题意:给出包含"()"和"[]"的括号序列,判断是否合法. 用栈来完成,注意空串就行. #include<iostream> #include< ...
- 平衡的括号 (Parentheses Balance UVA - 673)
题目描述: 原题:https://vjudge.net/problem/UVA-673 题目思路: 1.水题 2.栈+模拟 3.坑在有空串 AC代码 #include <iostream> ...
- Parentheses Balance (括号平衡)---栈
题目链接:https://vjudge.net/contest/171027#problem/E Yes的输出条件: 1. 空字符串 2.形如()[]; 3.形如([])或者[()] 分析: 1.设置 ...
- Leetcode 856. Score of Parentheses 括号得分(栈)
Leetcode 856. Score of Parentheses 括号得分(栈) 题目描述 字符串S包含平衡的括号(即左右必定匹配),使用下面的规则计算得分 () 得1分 AB 得A+B的分,比如 ...
- 2016年湖南省第十二届大学生计算机程序设计竞赛---Parenthesis(线段树求区间最值)
原题链接 http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1809 Description Bobo has a balanced parenthes ...
- CSU 1809 Parenthesis(线段树+前缀和)
Parenthesis Problem Description: Bobo has a balanced parenthesis sequence P=p1 p2-pn of length n and ...
- Codeforces Gym 100803G Flipping Parentheses 线段树+二分
Flipping Parentheses 题目连接: http://codeforces.com/gym/100803/attachments Description A string consist ...
- JavaScript: 世界上最被误解的语言|Douglas Crockford
JavaScript: 世界上最被误解的语言 JavaScript: The Wrrrld's Most Misunderstood Programming Language Douglas Croc ...
- CSU 1809 - Parenthesis - [前缀和+维护区间最小值][线段树/RMQ]
题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1809 Bobo has a balanced parenthesis sequenc ...
随机推荐
- Composer 安装和使用
1.linux下安装 curl -sS https://getcomposer.org/installer | php mv composer.phar /usr/local/bin/composer ...
- 树的dfs序.欧拉序
dfs序 ==先序,连续一段区间就是子树
- HTML5实现全屏API【进入和退出全屏】
现在主流浏览器基本上实现了全屏效果,但是不同浏览器实现不一样: [进入和退出全屏] // Webkit (works in Safari5.1 and Chrome 15)element.webkit ...
- mysql 架构~MGR监控手段
一 简介 今天咱们来聊聊MGR的监控 二 监控 方面: 1 节点mysql进程监控 2 节点mysql复制进程的监控 ...
- 经典]Linux内核中ioremap映射的透彻理解【转】
转自:http://blog.csdn.net/lanyang123456/article/details/7403514 几乎每一种外设都是通过读写设备上的寄存器来进行的,通常包括控制寄存器.状态寄 ...
- BLE获取iphone mac地址的方法--【原创】
本人用的BLE是TIcc2541,1.3.2协议栈 1.首先要说明的是,iphone手机将信息保护了,BLE设备读到的iphone地址是随机的,每次连接都会不同 2.下面我就具体说明如何查看手机的ma ...
- git操作之冲突解决
应用场景,任哥,我两个人共同修改了git项目上的一个文件.zsh命令行模式 准备工作 简写命令解释 gl=git pullgp=git pushgst=git statusgcmsg=git comm ...
- 数据库的连接使用——使用ADO.NET连接数据库
一.ADO.NET简介 ADO.NET是由很多类组成的一个类库,这些类库提供了很多对象,用来完成数据的连接.查询.插入.更新和删除等操作.其中主要包括以下对象: 1.Connection对象:用来连接 ...
- lnmp环境下piwiki网站流量分析工具的安装及配置
piwiki统计网站的安装 Piwik是一个PHP和MySQL的开放源代码的Web统计软件. 它给你一些关于你的网站的实用统计报告,比如网页浏览人数, 访问最多的页面, 搜索引擎关键词等等- Piwi ...
- ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061),mysql服务已启动
1 前言 在mysql服务已启动,用命令行进入或者heidisql工具都提示ERROR 2003 (HY000): Can't connect to MySQL server on 'localhos ...