UVA Parentheses Balance
来源:互联网 发布:战地3狙击枪械数据 编辑:程序博客网 时间:2024/05/22 02:19
题目如下:
Parentheses Balance
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
Yes
No
Yes
这道题我用STL中的链表做的,主要是为了可以方便地删除元素。我的思路是只要遇到()或[]就把这两个元素删除了,层层“剥下去”,如果能够剥到链表为空,则YES,反之NO。一个细节是要注意迭代器变量的值,删除后迭代器指向下一个元素,所以要将它自减以免漏掉元素。还有判断相邻两个元素的时候,迭代器会自加,要及时自减。另一个细节是可能直接输入一个空字符串,所以提前还要判断一下,因为这个WA了一次QAQ。
AC的代码如下:
- 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
- [转]cocos2d-x Socket
- 怎样在ubuntu中把windows设为默认启动项
- Java学习笔记_10_继承和多态
- 类成员函数,虚函数及虚函数表,内存布局
- Python中常用的字符串内建函数
- UVA Parentheses Balance
- 【中断异常】中断的响应和服务
- 关于Android中解析xml文件qName和localName的问题
- RPM 软件管理程序: rpm
- HTTP状态码
- 如何修改mysql root密码
- Java学习笔记_11_抽象类和接口
- JDK,JRE,JVM区别与联系
- java中的国际化