题目描述:

原题: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. IP Addressing

    IP Addressing(处理) Each host on Internet has unique 32 bit IP address Each address has two parts: net ...

  2. C#发送邮件类库

    public class Email { #region 发送邮件 /// <summary> /// 发送邮件 /// </summary> /// <param na ...

  3. Selenium基本用法以及元素定位

    一.Selenium 简介 Selenium是ThroughtWorks公司一个强大的开源Web功能测试工具系列,提供一套测试函数,用于支持Web自动化测试.函数非常灵活,能够完成界面元素定位.窗口跳 ...

  4. 【js】深拷贝和浅拷贝区别,以及实现深拷贝的方式

    一.区别:简单点来说,就是假设B复制了A,当修改A时,看B是否会发生变化,如果B也跟着变了,说明这是浅拷贝,如果B没变,那就是深拷贝. 此篇文章中也会简单阐述到栈堆,基本数据类型与引用数据类型,因为这 ...

  5. My collage goals

    PART ONE: THE GOALS OF GRADE ONE 1, Try my best to improve my GPA ,  keep it around 4.0 2, Learn mor ...

  6. JSP工作流程

    情况1:第一次请求一个页面 情况2:该页虽然是再次请求,但已经过修改 情况3:该页面是再次请求且未被修改

  7. LCD触屏驱动

    tiny4412多点触摸屏驱动程序(基于I2C协议): #include <linux/kernel.h> #include <linux/module.h> #include ...

  8. Leecode刷题之旅-C语言/python-169求众数

    /* * @lc app=leetcode.cn id=169 lang=c * * [169] 求众数 * * https://leetcode-cn.com/problems/majority-e ...

  9. java 深入理解引用类型

    该博客原创自某位博主,原创博客链接https://www.cnblogs.com/SilentCode/p/4858790.html 本人在全文通读的基础上修改了原文的一点小bug,并在原文基础上继续 ...

  10. C语言思维导图总结