UVaOJ673---Parentheses Balance
来源:互联网 发布:mac ps中的3d功能在哪 编辑:程序博客网 时间:2024/06/07 05:06
673 - Parentheses Balance
Time limit: 3.000 seconds
You are given a string consisting of parentheses () and []. A string of this type is said to be correct:
- (a)
- if it is the empty string
- (b)
- if A and B are correct, AB is correct,
- (c)
- if A is correct, (A) and [A] is correct.
Write a program that takes a sequence of strings of this type and check their correctness. Your program can assume that the maximum string length is 128.
Input
The file contains a positive integer n and a sequence of n strings of parentheses () and [], one string a line.Output
A sequence of Yes or No on the output file.Sample Input
3([])(([()])))([()[]()])()
Sample Output
YesNoYes
Miguel Revilla
2000-08-14
水题~~~~~~~~~~~~~~~~~~~~
#include <iostream>#include <stack>#include <string>using namespace std;int n;string str;enum Parentheses{ BRACKET, PARENTHESIS,};stack<Parentheses> parentheses;bool isYes;int main(){ cin>>n; cin.get(); while (n --) { while (! parentheses.empty()) { parentheses.pop(); } getline(cin, str); isYes = true; for (unsigned int i = 0; i < str.length(); i++) { if (str[i] == '(') { parentheses.push(PARENTHESIS); } else if (str[i] == '[') { parentheses.push(BRACKET); } else if (str[i] == ')') { if (parentheses.empty() || parentheses.top() != PARENTHESIS) { isYes = false; break; } else { parentheses.pop(); } } else if (str[i] == ']') { if (parentheses.empty() || parentheses.top() != BRACKET) { isYes = false; break; } else { parentheses.pop(); } } } if (! parentheses.empty()) { isYes = false; } if (isYes) { cout<<"Yes"<<endl; } else { cout<<"No"<<endl; } } return 0;}
- UVaOJ673---Parentheses Balance
- Parentheses Balance
- balance parentheses
- Parentheses Balance
- Parentheses Balance
- Parentheses Balance
- Parentheses Balance
- UVa 673 Parentheses Balance
- uva673 Parentheses Balance
- uva 673 - Parentheses Balance
- 673 - Parentheses Balance
- Uva 673 Parentheses Balance
- UVaOJ 673 - Parentheses Balance
- uva 673 - Parentheses Balance
- UVa 673 Parentheses Balance
- UVa 673 - Parentheses Balance
- 673 - Parentheses Balance
- UVA 673 Parentheses Balance
- UVaOJ10152---ShellSort
- 彻底卸载orcale
- 1AVA 实现Comparator 方法排序
- 在Visual Studio 2005下配置WinPcap开发环境
- flash与游戏笔记:国际化 (3)
- UVaOJ673---Parentheses Balance
- CSS语言详解——读书笔记
- U盘装系统中bios怎么设置USB启动
- javascriptOOP
- 欧几里得算法求最大公约数(九度刷题)
- VOD学习之TS 流中PAT PMT解析实例
- kyoto cabinet
- RSS订阅
- JMS与JBOSS