Parentheses Balance

题目链接:

https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=614

题意描述:

该题是判断所给的字符串括号是否匹配,如果匹配输出Yes若果是空串也输出Yes否则输出No

解题思路:

该题可以模拟栈的操作,当来一个右括号时,需要判断下左边是否与之相对应,如果对应继续往下比较,否则就结束比较,需要注意的就是空串的时候

程序代码:

#include<stdio.h>
#include<string>
#include<algorithm>
using namespace std;
#include<stack>char str[150],str0[150];int main()
{ int i,n,t;scanf("%d",&n);getchar(); while(n--){t=0;while(scanf("%c",&str[t]),str[t]!='\n'){t++;}str[t]='\0';t=0;for(i=0;str[i]!='\0';i++){str0[t]=str[i];if(str0[t]==')'&&str0[t-1]=='('||str0[t]==']'&&str0[t-1]=='[')t--;elset++;}if(t==0)printf("Yes\n");elseprintf("No\n");}return 0;
}

UVA-Parentheses Balance相关推荐

  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. Parentheses Balance UVA - 673(模拟)

    题目大意:类似于括号匹配. 思路:用栈简单模拟就行了,关键是怎么读入空格. 用getline(cin,str),就行了,如果读入的是空格怎么判断呢,只需要if(str[0]=='\0'),那么为什么不 ...

  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 ...

  10. 【紫书】UVA673 平衡的括号 Parentheses Balance

    题目提交点 UVA673 思路: 运用栈的思想,遇到'(' 和 ']' 入栈,遇到'('.'['出栈. 代码: #include<iostream> #include<stack&g ...

最新文章

  1. 100天59万行代码_如何抽出100天的代码时间
  2. C++回声服务器_5-多进程版本
  3. php cpu使用率,如何减低php程序的cpu使用率?
  4. python试卷(有答案版本、个人答案不是官方答案)_python试卷(有答案版本,个人答案不是官方答案).doc...
  5. mysql5.7.25数据库安装
  6. dlib人脸特征点对齐
  7. 领域情报搜索实践:真实场景下的问答实施策略与风险分析
  8. QT串口QSerialPort解决接收数据不完整问题
  9. MATLAB 检验矩阵中是否有某些元素 对元素统计
  10. VC文件读写操作总结
  11. 分享100佳精美的作品集网站设计案例
  12. api postmain 鉴权_API网关为什么要统一认证/鉴权?
  13. 鞋店商城小程序开发价值
  14. 创意h5游戏案例:记忆类H5手机游戏评测
  15. 汉字编码问题(附编码察看器)
  16. linux 获取文件父目录权限,Linux 文件权限中,操作一个文件需要父目录的那些权限?...
  17. 区块链 | 为什么说百度云BaaS是全新的云服务平台?
  18. Cast方法oracle,oracle 中cast方法的使用
  19. 数据链路层 (一)------ 计算机网络(三)
  20. 4G物联网卡的几点优势

热门文章

  1. 洛谷 P1396 营救
  2. centos7使用中文输入法
  3. 前端学习之路之CSS (三)
  4. mysql用户增删改
  5. 编译条件编译——判断当前使用的编译器及操作系统
  6. node之npm一直出错
  7. easyui弹出层在最顶层显示跳出iframe框架通用javascript代码
  8. 转:Real6410 Linux 常见问题总结(截至2010/07/26)
  9. 检索 COM 类工厂中 CLSID 为 {00024500-0000-0000-C000-000000000046} 的组件时失败,原因是出现以下错误: 80070005。...
  10. 栈实现队列(队列实现栈)