Parentheses Balance UVA - 673
Parentheses Balance UVA - 673
在网上看了很多题解,没看到用map做的(可能是我没找到吧)。其实用map可以少用很多if语句!
#include<cstdio>
#include<map>
#include<cstring>
#include<stack>
#include<iostream>
using namespace std;
int main()
{int n, i, l;char data[130];map<char, int> m;m.insert(pair<char, int>('[', 1));m.insert(pair<char, int>(']', -1));m.insert(pair<char, int>('(', 2));m.insert(pair<char, int>(')', -2));scanf("%d", &n);getchar();while (n--){/*fgets(data, 129, stdin);*/gets(data);l = strlen(data);stack<char> s;s.push('1');for (i = 0; i < l; i++){//printf("%c ",data[i]);if (m[s.top()] + m[data[i]] == 0 && m[data[i]] < 0)//应该是[ 对 ]的,而不是[ 对 [ ,另外要考虑到 ][s.pop();elses.push(data[i]);//printf("s.size()=%d ", s.size());}//printf("s.size()=%d ", s.size());if (s.size() == 1)printf("Yes\n");elseprintf("No\n");}return 0;
}
Parentheses Balance UVA - 673相关推荐
- Parentheses Balance UVA - 673(模拟)
题目大意:类似于括号匹配. 思路:用栈简单模拟就行了,关键是怎么读入空格. 用getline(cin,str),就行了,如果读入的是空格怎么判断呢,只需要if(str[0]=='\0'),那么为什么不 ...
- UVA 673-Parentheses Balance
UVA 673-Parentheses Balance 题目大意:1 A =[]或()算正确 2 A为BC(B,C都是正确的话)算正确 3 A = [M]或(M)(M为正确的话)算正确 解题思路:用栈 ...
- 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)
- 题目大意 给出两个字符()[],然后根据给的条件来判断. - 解题思路 根据给的三个条件,然后利用栈来处理,对于暂时没有后括号匹配的前括号压入栈,遇到后括号时看栈顶的前括号与其是否匹配,如果匹配则 ...
- 习题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 ...
最新文章
- 用 Python 详解《英雄联盟》游戏取胜的重要因素!
- Redis集群——利用Gearman在Lnmp架构中做MySQL的缓存服务器
- 锁死AI基础研究的两个「智子」是什么?
- mysql 非自然月统计_技本功|统计信息对SQL执行效率的影响
- c++ math头文件一些函数使用记录
- python之HTML文件转PDF文件,python之把HTML文件转换成PDF格式文档
- (附源码)spring boot西安市中小学生护眼平台开发 毕业设计 080855
- 快速排序C语言实现 - 源码详解
- python除法取商_python 除法
- Chrome利器之FireShot:网页长截图工具
- 试图通俗地讲一下庞加莱猜想是怎么回事
- 发送短信验证码时触发天级流控Premit:10
- 力扣刷题 DAY_73 回溯
- 从零开始制作一款打卡类小程序
- 在Unity中实现基于粒子的水模拟
- eve服务器关闭维护几天,关于维护请问,EVE每次维护的具体时间是多 – 手机爱问...
- MongoDb的ConnectionString链接字符串解析
- 实现JPanel切换
- tslearn使用轮廓系数(silhouette_score)评估KShape聚类效果
- 分享自己学英语的经验