平衡的括号 (Parentheses Balance 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)的更多相关文章
- Parentheses Balance UVA - 673
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 -SilverN
You are given a string consisting of parentheses () and []. A string of this type is said to be corr ...
- Parentheses Balance (括号平衡)---栈
题目链接:https://vjudge.net/contest/171027#problem/E Yes的输出条件: 1. 空字符串 2.形如()[]; 3.形如([])或者[()] 分析: 1.设置 ...
- 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 ...
- UVa 673 (括号配对) Parentheses Balance
本来是当做水题来做的,后来发现这道题略坑. 首先输入的字符串可能是空串,所以我用了gets函数,紧接着就被scanf("%d", &n)后面的换行符坑掉了. 于是乎再加一句 ...
- UVa 673 Parentheses Balance(栈的使用)
栈 Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Description You are ...
- UVa 673 平衡的括号
题意:给出包含"()"和"[]"的括号序列,判断是否合法. 用栈来完成,注意空串就行. #include<iostream> #include< ...
随机推荐
- webservice 从客户端中检测到有潜在危险的 Request.Form 值
webservice中传递xml格式的参数时报错 webservice 从客户端中检测到有潜在危险的 Request.Form 值解决方案: 1.在web.config的system.web节点中添加 ...
- synchronized 控制并发(活动秒杀)
1.首先我们新建一个Controller用于秒杀: package com.imooc.Controller; import com.imooc.service.impl.SeckillService ...
- DQL-排序查询
三:排序查询 语法: select 列名 from 表名 where 筛选条件 order by 需要排序的列名 asc/desc 特点:不写升序还是降序,默认升序 排序列表 可以是 ...
- 给出一个整数,将这个整数中每位上的数字进行反转(JavaScript编程)
一.问题描述:给出一个整数,将这个整数中每位上的数字进行反转.示例:输入:123,输出321:输入-123,输出-321:输入120,输出-21 二.问题分析与解决: 需要将给出的整数反转,注意示例中 ...
- SSM整合时初始化出现异常
java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException ...
- Java实现“睡排序”——线程池Executors的使用
前提 之前在知乎上看见一个有意思的排序算法——睡排序. 睡排序最早好像是4chan上一个用户用shell脚本实现的: 算法思想简洁明了:利用进程的sleep来实现 越大的数字越迟输出. 虽然像2L说的 ...
- 一道关于js正则表达式的面试题
这道面试题明显是要用到正则表达式来解决的,由于太久没有写正则表达式了,一时之间竟然写不出来,所以记录一下笔记,下面直接上代码: function parseUrl(str) { // 判断是否传入参数 ...
- 农民工自学java到找到工作的前前后后
我是一名地地道道的农民工,生活在经济落后的农村,有一个哥哥和一个弟弟,父母都是地道的农民,日出而作,日落而息,我从小到大学习一直很好,从小学到高一都,成绩在全级一直名列前茅,这样我也顺利了考上省的重点 ...
- ecshop 后台添加新菜单 以及 权限控制
首先 在languages\zh_cn\admin\common.php 中添加 一级菜单 二级菜单 其次 在admin\includes\inc_menu.php 中添加 然后 在admin\inc ...
- Delphi并行库System.Threading 之ITask 1
不知什么时候,也许是XE8,也许是XE8之前 .Delphi里面多了个System.Threading的并行库. 虽然己经有非常棒的第三方并行库QWorker,但我还是更喜欢官方的东西. 下面是一段使 ...