【习题 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 ...
随机推荐
- Mybatis使用注解进行增删改查
// 增public interface StudentMapper{ @Insert("insert into student (stud_id, name, email, addr_id ...
- AJAX 删除数据
var json = { "id":"12", "name":"admin"}$.ajax({ type: " ...
- UNIX多线程编程
一个程序至少有一个进程.一个进程至少有一个线程.进程拥有自己独立的存储空间,而线程能够看作是轻量级的进程,共享进程内的全部资源.能够把进程看作一个工厂.线程看作工厂内的各个车间,每一个车间共享整个工厂 ...
- J2EE之13个规范标准概念
主要是关于j2EE十三个规范的总结. java基础知识 首先java分为三类:J2ME.J2SE.J2EE. 依据开发软件的大小和量级他们的作用分别不同,J2ME是开发为机顶盒.移动电话和PDA之类嵌 ...
- shape-自绘制简单图形
shape 可以绘制简单的图形,颜色等.它主要就是应用于selector 的一些状态. 本文内容参考自http://www.cnblogs.com/cyanfei/archive/2012/07/27 ...
- geotif格式的波段描述信息探究
作者:朱金灿 来源:http://blog.csdn.net/clever101 有时打开一些geotif文件,可以看到它的波段描述,但是它究竟存储在文件的什么位置呢?今天研究了一下,大致搞清了这个问 ...
- Linux下几种另类创建文件之方法
以前我们用编辑器例如vi来新建文件,下面介绍几种另类生成文件的方法,多用在备份和测试上. 创建文件的方法: 1.echo 命令 #echo "set bell" >& ...
- Sparse Coding: Autoencoder Interpretation
稀疏编码 在稀疏自编码算法中,我们试着学习得到一组权重参数 W(以及相应的截距 b),通过这些参数可以使我们得到稀疏特征向量 σ(Wx + b) ,这些特征向量对于重构输入样本非常有用. 稀疏编码可以 ...
- Oracle定义变量、常量
1 定义变量 declare var_countryname varchar2(50):='中国'; 2 定义常量 con_day constant integer:=365;
- 怎样利用ash监控会话
ash是很有效的监控工具之中的一个.1秒抓一次 select max(sample_time)over(),min(sample_time)over() from dba_hist_active_se ...