平衡的括号 (Parentheses Balance UVA - 673)
题目描述:
题目思路:
1.水题
2.栈+模拟
3.坑在有空串
AC代码
#include <iostream>
#include <stack>
using namespace std; int main(int argc, char *argv[])
{
int t;
scanf("%d",&t);
getchar();
while(t--)
{
string buf;
stack<char> s;
getline(cin,buf);
int len = buf.size();
int i ,flag = ;
for(i = ;i < len;i ++)
{
if(buf[i] == '(' || buf[i] == '[') s.push(buf[i]) ;
else if(!s.empty() && s.top()=='('&&buf[i]==')') s.pop() ;
else if(!s.empty() && s.top()=='['&&buf[i]==']') s.pop() ;
else flag = ;
}
if(!flag && !s.size()) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
return ;
}
平衡的括号 (Parentheses Balance UVA - 673)的更多相关文章
- Parentheses Balance UVA - 673
You are given a string consisting of parentheses () and []. A string of this type is said to be corr ...
- UVa 673 Parentheses Balance
一个匹配左右括号的问题 /*UVa 673 Parentheses Balance*/ #include<iostream> #include<algorithm> #incl ...
- UVa 673 Parentheses Balance -SilverN
You are given a string consisting of parentheses () and []. A string of this type is said to be corr ...
- Parentheses Balance (括号平衡)---栈
题目链接:https://vjudge.net/contest/171027#problem/E Yes的输出条件: 1. 空字符串 2.形如()[]; 3.形如([])或者[()] 分析: 1.设置 ...
- UVa673 Parentheses Balance
// UVa673 Parentheses Balance // 题意:输入一个包含()和[]的括号序列,判断是否合法. // 具体递归定义如下:1.空串合法:2.如果A和B都合法,则AB合法:3.如 ...
- UVA 673 (13.08.17)
Parentheses Balance You are given a string consisting of parentheses () and []. Astring of this ty ...
- UVa 673 (括号配对) Parentheses Balance
本来是当做水题来做的,后来发现这道题略坑. 首先输入的字符串可能是空串,所以我用了gets函数,紧接着就被scanf("%d", &n)后面的换行符坑掉了. 于是乎再加一句 ...
- UVa 673 Parentheses Balance(栈的使用)
栈 Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Description You are ...
- UVa 673 平衡的括号
题意:给出包含"()"和"[]"的括号序列,判断是否合法. 用栈来完成,注意空串就行. #include<iostream> #include< ...
随机推荐
- 【转载】对C#DateTime的一些扩展,计算周内第一天,最后一天
/// <summary> /// DateTime的一些扩展 /// </summary> public class DateTime2 { /// <summary& ...
- Entity Framework code first设置不在数据库中生成外键
你现在用的EF是什么版本?我用EF6,你可以重写SqlServerMigrationSqlGenerator的生成外键和更新外键的方法,把不需要的表都过滤掉不就ok了? public class Ex ...
- java 编写小工具 尝试 学习(五)
1.今天 学习 标签 的 控件 的使用 ,学习 视频教程 参考 :http://edu.51cto.com/lesson/id-17733.html 常用控件如下截图: import javax.s ...
- tomcat解析
tomat是一个servlet容器,来处理http请求.在平时的使用中我们都会再浏览器中输入http地址来访问服务资源,比如格式http://host[":"port][abs_p ...
- Unity 游戏框架搭建 (二十一) 使用对象池时的一些细节
上篇文章使用SafeObjectPool实现了一个简单的Msg类.代码如下: class Msg : IPoolAble,IPoolType { #region IPoolAble 实现 public ...
- js取一个对象中的另一个对象
最开始的截图 原本是想取到其中的foodName 先是用一个for循环循环了下 for (var i=0;i<res.data.length;i++) { this.goodsList.res. ...
- 通过ES6写法去对Redux部分源码解读
在Redux源码中主要有四个文件createStore,applyMiddleware,bindActionCreators,combineRedures createStore.js export ...
- TeamViewer13个人版使用中提示为商用版导致无法使用
前言:由于使用teamviewer个人免费版较频繁,被软件识别到不能再继续免费使用,无奈没有多余的资金进行购买正版软件, 通过鼓捣得到如下继续免费使用方案,整理下来以备不时之需,也可以被有同此困惑的朋 ...
- Mysql慢查询开启和查看 ,存储过程批量插入1000万条记录进行慢查询测试
首先登陆进入Mysql命令行 执行sql show variables like 'slow_query%'; 结果为OFF 说明还未开启慢查询 执行sql show varia ...
- linux3.4.2之块设备驱动完整程序
/*参考drivers/block/xd.c *以及drivers/block/z2ram.c */ #include <linux/module.h> #include <linu ...