【习题 6-1 UVA-673】Parentheses Balance
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
括号匹配。
栈模拟就好。
多种括号也是一样可以做的。
【代码】
#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的更多相关文章
- UVa 673 Parentheses Balance -SilverN
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(栈的使用)
栈 Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Description You are ...
- UVa 673 Parentheses Balance【栈】
题意:输入一个包含"()"和"[]"的序列,判断是否合法 用栈来模拟,遇到"(",“[”就入栈,遇到')',']'就取出栈顶元素看是否匹配, ...
- UVA 673 Parentheses Balance (栈)
题意描述: 给出一段只包含()和[]的字符串,判断是否合法,合法输出YES,不合法输出NO 规则: 1.该串为空,则合法 2.若A合法,B合法,则AB合法 3.若A合法,则(A)和[A]均合法 解题思 ...
- UVa 673 Parentheses Balance (stack)
题目描述 : 判断字符串是不是符合正确的表达式形式. 要点 : 考虑字符串为空的时候,用getline输入,每一次判断后如果为No则要清空栈.对称思想. 注意输入格式. 代码: #include &l ...
- 【UVA】673 Parentheses Balance(栈处理表达式)
题目 题目 分析 写了个平淡无奇的栈处理表达式,在WA了5发后发现,我没处理空串,,,,(或者说鲁棒性差? 代码 #include <bits/stdc++.h> usin ...
- 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 ...
- Parentheses Balance UVA - 673
You are given a string consisting of parentheses () and []. A string of this type is said to be corr ...
随机推荐
- chgrp---改变文件或目录所属的用户组
chgrp命令用来改变文件或目录所属的用户组.该命令用来改变指定文件所属的用户组.其中,组名可以是用户组的id,也可以是用户组的组名.文件名可以 是由空格分开的要改变属组的文件列表,也可以是由通配符描 ...
- UVALive 6867 Plane Ticket Pricing
Plane Ticket Pricing Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu ...
- 获取cpu使用率
http://blog.csdn.net/u010515761/article/details/43225621 http://stackoverflow.com/questions/74674/ho ...
- Eclipse+PyDev解决中文输入和注释问题
Eclipse的设置 window->preferences->general->editors->text editors->spelling->encoding ...
- 用Shell脚本过滤Hadoop中不能訪问的节点
近期使用的一个集群hp1,由于维护集群的人不给力.节点总是过一段时间就掉一两个.今天发现重新启动hadoop时,HDFS已经进入保护模式了. 决定把slaves节点中的无法訪问的节点所有过滤掉.所以写 ...
- BZOJ 刷题记录 PART 5
拖了好久才写的. [BZOJ2821]接触分块大法.这道题略有点新颖.首先我们先分块.然后统计每块中每一个数出现的个数. 以下是联立各个方块,预处理出第I个方块到第J个方块出现正偶数次数的个数. fo ...
- android图像处理系列之四-- 给图片添加边框(上)
图片处理时,有时需要为图片加一些边框,下面介绍一种为图片添加简单边框的方法. 基本思路是:将边框图片裁剪成八张小图片(图片大小最好一致,不然后面处理会很麻烦),分别对应左上角,左边,左下角,下边,右下 ...
- 深入理解Android(1)——理解Android中的JNI(上)
我参加了CSDN博客之星评选,如果在过去的一段时间里阳光小强的博客对你有所帮助,在这里希望能投上您宝贵的一票,每天都可以投一次:http://vote.blog.csdn.net/blogstar20 ...
- c# array arraylist 泛型list
1 array 数组 是存储相同类型元素的固定大小的数据的顺序集合.在内存中是连续存储的,所以索引速度非常快,而且赋值和修改元素也非常简单. //定义字符串数组 大小为3 string[] str1 ...
- [PWA] Deal with caches in PWA
The takeway is to know when we should cache the content? When we should clean the caches? 1. When sh ...