【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

括号匹配。
栈模拟就好。
多种括号也是一样可以做的。

【代码】

#include <bits/stdc++.h>
using namespace std; const int N = 150; stack <char> sta;
string s; int main() {
#ifdef LOCAL_DEFINE
freopen("F:\\c++source\\rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0),cin.tie(0);
int T;
cin >> T;cin.get();
while (T--) {
while (!sta.empty()) sta.pop();
getline(cin,s);
int n= s.size();
int ok = 1;
for (int i = 0;i < n;i++){
if (s[i]=='(' || s[i] == '[')
sta.push(s[i]);
else if (!sta.empty() && sta.top()=='(' && s[i]==')') sta.pop();
else if (!sta.empty() && sta.top()=='[' && s[i]==']') sta.pop();
else ok = 0;
}
if (!sta.empty()) ok = 0;
if (!ok){
cout << "No" << endl;
}else{
cout << "Yes"<<endl;
}
} return 0;
}

【习题 6-1 UVA-673】Parentheses Balance的更多相关文章

  1. UVa 673 Parentheses Balance -SilverN

    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(栈的使用)

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

  4. UVa 673 Parentheses Balance【栈】

    题意:输入一个包含"()"和"[]"的序列,判断是否合法 用栈来模拟,遇到"(",“[”就入栈,遇到')',']'就取出栈顶元素看是否匹配, ...

  5. UVA 673 Parentheses Balance (栈)

    题意描述: 给出一段只包含()和[]的字符串,判断是否合法,合法输出YES,不合法输出NO 规则: 1.该串为空,则合法 2.若A合法,B合法,则AB合法 3.若A合法,则(A)和[A]均合法 解题思 ...

  6. UVa 673 Parentheses Balance (stack)

    题目描述 : 判断字符串是不是符合正确的表达式形式. 要点 : 考虑字符串为空的时候,用getline输入,每一次判断后如果为No则要清空栈.对称思想. 注意输入格式. 代码: #include &l ...

  7. 【UVA】673 Parentheses Balance(栈处理表达式)

    题目 题目     分析 写了个平淡无奇的栈处理表达式,在WA了5发后发现,我没处理空串,,,,(或者说鲁棒性差?     代码 #include <bits/stdc++.h> usin ...

  8. UVa673 Parentheses Balance

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

  9. UVA 673 (13.08.17)

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

  10. Parentheses Balance UVA - 673

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

随机推荐

  1. 直接修改Android软件数据库来改变软件设置实例一则

    昨天把K860i刷了机,刷到了最新的CyanogenMod 10.1,使用起来各种流畅舒服,不过却由于内外置SD卡的挂载点的改变,造成了一些困扰,现记录如下.         平时里由于极少把手机连接 ...

  2. 51nod 子序列的个数 (动规分析方法)

    这道题的分析方法我很需要学习学习. 一开始我想的是f[i][j]表示前i个数子序列长度为j的个数 然后发现新加入一个数的时候会和前面的重复,这个时候不知道该怎么处理这种重复. 其实我再继续往下想就可以 ...

  3. web——前后端通信

    前端向后台传输数据: 传输方法:post  get 区别: (1)get:用于从服务器获取数据,将参数数据队列加到提交表单的ACTION属性所指的URL中,值和表单内各个字段一一对应,在URL中可以看 ...

  4. jmind-redis一个redis的nio客户端

    Redis是一个基于key/value的系统.Redis目前最新版本是2.2.4,用着很不错,不过java版本的客户端比较的不给力,目前redis 客户端jedis 是基于io 的socket . 而 ...

  5. Apache shiro 笔记整理之web整合一

    下面内容是在看了涛哥的<跟我一起学shiro> 和 视频<一头扎入进shiro> 后整理出来备忘和方便自己和其它人学习. 个人主页:http://www.itit123.cn/ ...

  6. uva725(除法)

    Description Write a program that finds and displays all pairs of 5-digit numbers that between them u ...

  7. 深入理解Android(3)——Eclipse集成javah和NDK-Builder

    在上一篇文章中我们使用了javah工具来生成了native java文件所对应的C++头文件,但是这样生成比较麻烦,我们这一篇来介绍如何在eclipse中集成javah和NDK-Builder. 一. ...

  8. Vagrant 和 docker

    Docker应用实践 http://dockerone.com/article/146 Vagrant 适合用来管理虚拟机,而docker适合用来管理应用环境 http://www.linuxidc. ...

  9. Oracle 11g win7 64位【桌面类 && 服务器类】安装过程

    Oracle 11g  win7  64位[桌面类 && 服务器类]安装过程  一.首先,根据自己的操作系统位数(32位或64位),到官网下载相应的安装程序,如下图所示.       ...

  10. 最大子矩阵和 51Nod 1051 模板题

    一个M*N的矩阵,找到此矩阵的一个子矩阵,并且这个子矩阵的元素的和是最大的,输出这个最大的值. 例如:3*3的矩阵:   -1 3 -1 2 -1 3 -3 1 2   和最大的子矩阵是:   3 - ...