题目大意:类似于括号匹配。
思路:用栈简单模拟就行了,关键是怎么读入空格。
用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(模拟)相关推荐

  1. Parentheses Balance UVA - 673

    Parentheses Balance UVA - 673 在网上看了很多题解,没看到用map做的(可能是我没找到吧).其实用map可以少用很多if语句! #include<cstdio> ...

  2. UVA 673-Parentheses Balance

    UVA 673-Parentheses Balance 题目大意:1 A =[]或()算正确 2 A为BC(B,C都是正确的话)算正确 3 A = [M]或(M)(M为正确的话)算正确 解题思路:用栈 ...

  3. UVa673 - Parentheses Balance

    //UVa673 - Parentheses Balance //已AC #include<iostream> #include<string> #include<sta ...

  4. uva 673 Parentheses Balance

    原题: You are given a string consisting of parentheses () and []. A string of this type is said to be ...

  5. B - Parentheses Balance (UVA - 673)

    - 题目大意 给出两个字符()[],然后根据给的条件来判断. - 解题思路 根据给的三个条件,然后利用栈来处理,对于暂时没有后括号匹配的前括号压入栈,遇到后括号时看栈顶的前括号与其是否匹配,如果匹配则 ...

  6. 习题6-1 平衡的括号(Parentheses Balence,UVa 673)

    原题链接:https://vjudge.net/problem/UVA-673 分类:栈 备注:水题 分析:简单的大学课本里都有的认识栈的第一步. #include<iostream> # ...

  7. 【uva-673】 Parentheses Balance(括号匹配问题)

    题干: You are given a string consisting of parentheses () and []. A string of this type is said to be  ...

  8. Parentheses Balance (括号平衡)---栈

    题目链接:https://vjudge.net/contest/171027#problem/E Yes的输出条件: 1. 空字符串 2.形如()[]; 3.形如([])或者[()] 分析: 1.设置 ...

  9. uva673 Parentheses Balance

    题意:看括号是否匹配 解题思路:一直想用递归来做,发现做不出  后来才想到消去当今可以消去的() 与 [] 的括号  循环找就行了 #include <stdlib.h> #include ...

最新文章

  1. golang内置接口error
  2. Android -- 再来一发Intent
  3. 51Nod- 1915 西湖游船
  4. MATLAB基本操作(七):有关文件路径的几个函数在编程中的作用
  5. Hadoop学习笔记03_Hive练习
  6. 一位算法工程师从30+场秋招面试中总结出的超强面经—文本检测与GAN篇(含答案)...
  7. 揭秘:微信如何用libco支撑8亿用户?
  8. 工作 3 年和读研 3 年哪个更值?
  9. 电机调速程序c语言,直流电机调速控制系统的C语言程序
  10. 有趣的硬币 java_有趣的硬币作文
  11. pyinstaller(py文件转成exe)
  12. 还原扩容的缩水U盘真实容量方法,让数据免受损失
  13. 看待FIL能否成功不应该只关注它的币价,而是IPFS能否完全落地应用……
  14. 源码看JAVA【五】Byte
  15. SAE J3016 自动驾驶分级定义 2021年4月更新
  16. ubuntu下无线网卡解决经历
  17. 将汉字转换为拼音:pypinyin.pinyin()
  18. 全景分割相关论文写作与准备笔记
  19. ddr4 dqs 频率_DDR4各种技术参数详解
  20. 腾讯云大老亲码“Spring深度笔记”,不讲一句废话,全是精华

热门文章

  1. 怎么换外网IP地址 如何设置代理服务器上网
  2. js replace 中文分号_在JS中用Replace 全部替换字符
  3. 6.pixi.js编写的塔防游戏(类似保卫萝卜)-游戏资源打包逻辑
  4. 基于STC89C52单片机的脉搏测量仪设计
  5. coins feast 题解_feast英语月考阅读理解
  6. win10 硬盘占用率经常100%的可能有用的解决方案
  7. 专题学习1 Cproblem—马走日
  8. 公司有个技术大拿,别人加班他不加,老板:真当我不敢辞退你吗?
  9. java蓝桥杯练习 星际交流
  10. cf 340C 差值递推