Parentheses Balance UVA - 673(模拟)
题目大意:类似于括号匹配。
思路:用栈简单模拟就行了,关键是怎么读入空格。
用getline(cin,str),就行了,如果读入的是空格怎么判断呢,只需要if(str[0]==’\0’),那么为什么不是\n呢,因为getline在读的时候就将\n转化为\0了;
代码:
#include<iostream>
#include<string>
#include<stack>
#include<sstream>
#include<fstream>
using namespace std;
int n;
int main(){cin>>n;getchar();while(n--){stack<char>st;string str;getline(cin,str); for(int i=0;i<str.size();i++){if(str[i]==']'&&!st.empty()&&st.top()=='['){st.pop();}else if(str[i]==')'&&!st.empty()&&st.top()=='('){st.pop();}else{st.push(str[i]);}}if(!st.empty()){cout<<"No"<<endl;}else{cout<<"Yes"<<endl;}}
}
Parentheses Balance UVA - 673(模拟)相关推荐
- Parentheses Balance UVA - 673
Parentheses Balance UVA - 673 在网上看了很多题解,没看到用map做的(可能是我没找到吧).其实用map可以少用很多if语句! #include<cstdio> ...
- 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 ...
最新文章
- golang内置接口error
- Android -- 再来一发Intent
- 51Nod- 1915 西湖游船
- MATLAB基本操作(七):有关文件路径的几个函数在编程中的作用
- Hadoop学习笔记03_Hive练习
- 一位算法工程师从30+场秋招面试中总结出的超强面经—文本检测与GAN篇(含答案)...
- 揭秘:微信如何用libco支撑8亿用户?
- 工作 3 年和读研 3 年哪个更值?
- 电机调速程序c语言,直流电机调速控制系统的C语言程序
- 有趣的硬币 java_有趣的硬币作文
- pyinstaller(py文件转成exe)
- 还原扩容的缩水U盘真实容量方法,让数据免受损失
- 看待FIL能否成功不应该只关注它的币价,而是IPFS能否完全落地应用……
- 源码看JAVA【五】Byte
- SAE J3016 自动驾驶分级定义 2021年4月更新
- ubuntu下无线网卡解决经历
- 将汉字转换为拼音:pypinyin.pinyin()
- 全景分割相关论文写作与准备笔记
- ddr4 dqs 频率_DDR4各种技术参数详解
- 腾讯云大老亲码“Spring深度笔记”,不讲一句废话,全是精华