题目描述:

原题:https://vjudge.net/problem/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)的更多相关文章

  1. Parentheses Balance UVA - 673

    You are given a string consisting of parentheses () and []. A string of this type is said to be corr ...

  2. UVa 673 Parentheses Balance

    一个匹配左右括号的问题 /*UVa 673 Parentheses Balance*/ #include<iostream> #include<algorithm> #incl ...

  3. UVa 673 Parentheses Balance -SilverN

    You are given a string consisting of parentheses () and []. A string of this type is said to be corr ...

  4. Parentheses Balance (括号平衡)---栈

    题目链接:https://vjudge.net/contest/171027#problem/E Yes的输出条件: 1. 空字符串 2.形如()[]; 3.形如([])或者[()] 分析: 1.设置 ...

  5. UVa673 Parentheses Balance

    // UVa673 Parentheses Balance // 题意:输入一个包含()和[]的括号序列,判断是否合法. // 具体递归定义如下:1.空串合法:2.如果A和B都合法,则AB合法:3.如 ...

  6. UVA 673 (13.08.17)

     Parentheses Balance  You are given a string consisting of parentheses () and []. Astring of this ty ...

  7. UVa 673 (括号配对) Parentheses Balance

    本来是当做水题来做的,后来发现这道题略坑. 首先输入的字符串可能是空串,所以我用了gets函数,紧接着就被scanf("%d", &n)后面的换行符坑掉了. 于是乎再加一句 ...

  8. UVa 673 Parentheses Balance(栈的使用)

     栈 Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu   Description You are ...

  9. UVa 673 平衡的括号

    题意:给出包含"()"和"[]"的括号序列,判断是否合法. 用栈来完成,注意空串就行. #include<iostream> #include< ...

随机推荐

  1. 从零开始学习CocoaPods安装和使用

    从零开始学习CocoaPods安装和使用   转载: Code4App原创:http://code4app.com/article/cocoapods-install-usage http://m.i ...

  2. Vue教程:计算属性computed与侦听器watch(三)

    计算属性computed 模板内的表达式非常便利,但是设计它们的初衷是用于简单运算的.在模板中放入太多的逻辑会让模板过重且难以维护.例如: <div id="example" ...

  3. Spark集群新增节点方法

    Spark集群处理能力不足需要扩容,如何在现有spark集群中新增新节点?本文以一个实例介绍如何给Spark集群新增一个节点. 1. 集群环境 现有Spark集群包括3台机器,用户名都是cdahdp, ...

  4. 【js】中的小技巧

    本文主要介绍一些JS中用到的小技巧 1. 类型强制转换   1.1 string强制转换为数字 可以用*1来转化为数字(实际上是调用.valueOf方法) 然后使用Number.isNaN来判断是否为 ...

  5. 【usaco】1.1

    你的飞碟在这儿Your Ride Is Here(难度:入门难度) 题目链接 题目大意 emmmm 输入两个字符串,问他们每个字母的asco码相乘后字符串是否相等. 思路 一道水题?(雾) 错误代码: ...

  6. .Net core 使用TimeJob

    在我以前的文章中有一个.Net core使用Quartz.Net ,一开始我们的设想就是定时操作数据库,所以有很多实现方法,后来发现TimeJob可以同样实现我们的需求,而且更简便. 所以我们就使用了 ...

  7. Python记录键盘鼠标敲击次数

    Idea 作为一个每天有一半时间都在电脑旁的人,无时无刻不在敲击着键盘,点击着鼠标.有一天,我突然很想知道在一天的时间内,在我轻盈的指法下面,键盘被我狂敲了多少下,鼠标又被我点击了多少次.甚至更具体一 ...

  8. Java软件开发者,如何学习大数据?

    正常来讲学习大数据之前都要做到以下几点 1.学习基础的编程语言(java,python) 2.掌握入门编程基础(linux操作,数据库操作.git操作) 3.学习大数据里面的各种框架(hadoop.h ...

  9. 使用GlobalKey启动APP

    按键输入有三种:system key  音量键 global key 按下启动某个APP user key  ABCD... 给安卓应用程序定义一个广播接收者,写一个BroadcastReceiver ...

  10. 记springboot+mybatis+freemarker+bootstrap的使用(1)

    一..springboot的配置 1.安装并配置maven maven是项目管理工具,可以自动下载并管理jar包之间的依赖关系,可通过maven自动配置springboot 参照百度经验https:/ ...