UVA 673-Parentheses Balance
UVA 673-Parentheses Balance
题目大意:1 A =[]或()算正确 2 A为BC(B,C都是正确的话)算正确 3 A = [M]或(M)(M为正确的话)算正确
解题思路:用栈存([,遇到)]相消
#include <stdio.h>
#include <iostream>
#include <stack>
using namespace std;
int main() {int n;char a;cin >> n;getchar();while(n--) {stack<int> s;int r = 1;while((a = getchar()) != '\n') {if(a == '(' || a == '[')s.push(a);else if(a == ')') {if(!s.empty() && s.top() == '(')s.pop();else {r = 0;}}else if(a == ']') {if(!s.empty() && s.top() == '[')s.pop();else {r = 0;}}}if(!s.empty())r = 0;if(r == 0)printf("No\n");else printf("Yes\n");}return 0;
}
UVA 673-Parentheses Balance相关推荐
- Parentheses Balance UVA - 673
Parentheses Balance UVA - 673 在网上看了很多题解,没看到用map做的(可能是我没找到吧).其实用map可以少用很多if语句! #include<cstdio> ...
- UVa673 - Parentheses Balance
//UVa673 - Parentheses Balance //已AC #include<iostream> #include<string> #include<sta ...
- uva 673 Parentheses Balance
原题: You are given a string consisting of parentheses () and []. A string of this type is said to be ...
- B - Parentheses Balance (UVA - 673)
- 题目大意 给出两个字符()[],然后根据给的条件来判断. - 解题思路 根据给的三个条件,然后利用栈来处理,对于暂时没有后括号匹配的前括号压入栈,遇到后括号时看栈顶的前括号与其是否匹配,如果匹配则 ...
- Parentheses Balance UVA - 673(模拟)
题目大意:类似于括号匹配. 思路:用栈简单模拟就行了,关键是怎么读入空格. 用getline(cin,str),就行了,如果读入的是空格怎么判断呢,只需要if(str[0]=='\0'),那么为什么不 ...
- 习题6-1 平衡的括号(Parentheses Balence,UVa 673)
原题链接:https://vjudge.net/problem/UVA-673 分类:栈 备注:水题 分析:简单的大学课本里都有的认识栈的第一步. #include<iostream> # ...
- 【uva-673】 Parentheses Balance(括号匹配问题)
题干: You are given a string consisting of parentheses () and []. A string of this type is said to be ...
- Parentheses Balance (括号平衡)---栈
题目链接:https://vjudge.net/contest/171027#problem/E Yes的输出条件: 1. 空字符串 2.形如()[]; 3.形如([])或者[()] 分析: 1.设置 ...
- uva673 Parentheses Balance
题意:看括号是否匹配 解题思路:一直想用递归来做,发现做不出 后来才想到消去当今可以消去的() 与 [] 的括号 循环找就行了 #include <stdlib.h> #include ...
最新文章
- 最好用的货币:货币发展史和BCH
- mysql客户端与服务端_mysql语句在客户端与服务端的基本使用
- python中硬要写抽象类和抽象方法
- CRM WebClient UI里标准configuration和custom configuration区别
- Beetlex之tcp/tls服务压测工具
- 设计模式之—访问者模式VisitorPattern
- c语言程序设计备考,《C语言程序设计》复习资料.doc
- saltstack的探索-salt指定目标和分组
- springboot+mybatis+shiro+beetl前端做 服务监控页面
- 开源推荐:表单收集系统-TDuck填鸭 v2版本!
- numpy返回上下三角矩阵
- 红帽子企业Linux 5安装序列号
- 一个程序猿小小的梦想-写在16年底的时候
- PCB genesis 大孔扩孔(不用G84命令)实现方法
- Android自定义星星评分控件,高效
- 一种新型分割图像中人物的方法,基于人物动作辨认
- 用matlab实现熵权法,熵权法原理及matlab代码实现
- PSO粒子群算法优化BP神经网络(PSO-BPNN)回归预测MATLAB代码
- STM32使用Jlink下载出现NO cortex-M SW device Found解决(超详细)
- ARM 立即寻址之立即数的形成 —— 如何判断有效立即数