UVa 673 - Parentheses Balance
来源:互联网 发布:塘厦cnc编程招聘 编辑:程序博客网 时间:2024/04/25 13:54
题目:括号匹配的合法判断。
分析:简单题、栈。
注意:输出空行。
#include <iostream>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <stack> using namespace std;string str;int main(){int n;while ( cin >> n ) {getchar();while ( n -- ) {getline(cin,str);stack<char>S;int L = str.length();int e = 0;int flag = 1;for ( int i = 0 ; i < L ; ++ i ) {if ( str[i] == '(' || str[i] =='[' )S.push(str[i]);if ( str[i] == ']' ) {if ( !S.empty() && S.top() == '[' )S.pop();else {flag = 0;break;}}if ( str[i] == ')' ) {if ( !S.empty() && S.top() == '(' )S.pop();else {flag = 0;break;}}}if ( flag && S.empty() )cout << "Yes" << endl;else cout << "No" << endl;}}return 0;}
- UVa 673 Parentheses Balance
- uva 673 - Parentheses Balance
- Uva 673 Parentheses Balance
- uva 673 - Parentheses Balance
- UVa 673 Parentheses Balance
- UVa 673 - Parentheses Balance
- UVA 673 Parentheses Balance
- UVa 673 - Parentheses Balance
- UVA 673 Parentheses Balance
- UVa 673 - Parentheses Balance
- Uva-673-Parentheses Balance
- UVa 673 - Parentheses Balance
- uva 673Parentheses Balance
- uva-673 Parentheses Balance
- UVA 673 Parentheses Balance
- UVa 673 - Parentheses Balance
- uva 673 - Parentheses Balance
- uva 673 Parentheses Balance
- database and os was hang with ORA-240 ERROR(bug6270137,10207611 )
- Eclipse安装插件Properties Editor
- 启动MySQL 监视器(Monitor) 【数据库高效编程 - 学习笔记 第三章】
- POJ 2752(不满足P[i]<>P[next[i]] 的next函数)
- Java分页 pager_taglib标签库分页
- UVa 673 - Parentheses Balance
- Android开发获取ImageView中的图片
- 获得传入日期的下一天
- 修复 artDialog 双击遮罩层就会自动关闭的bug.... 自己动手....
- Oracle drop user xxx cascade
- Linux curl使用简单介绍
- System.arraycopt(Object src,int srcPos,Object dest,int destPos,int length)
- 关于 su 和 sudo
- 也比较一下PG中的like查询: like '%<str>%'