ACM 括号匹配问题,为什么一定要用栈来写?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) an
来源:学生作业帮助网 编辑:作业帮 时间:2024/07/12 13:13:12
![ACM 括号匹配问题,为什么一定要用栈来写?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) an](/uploads/image/z/15222030-6-0.jpg?t=ACM+%E6%8B%AC%E5%8F%B7%E5%8C%B9%E9%85%8D%E9%97%AE%E9%A2%98%2C%E4%B8%BA%E4%BB%80%E4%B9%88%E4%B8%80%E5%AE%9A%E8%A6%81%E7%94%A8%E6%A0%88%E6%9D%A5%E5%86%99%3FYou+are+given+a+string+consisting+of+parentheses+%28%29+and+%5B%5D.A+string+of+this+type+is+said+to+be+correct%3A%28a%29if+it+is+the+empty+string%28b%29if+A+and+B+are+correct%2CAB+is+correct%2C%28c%29if+A+is+correct%2C%28A%29+an)
ACM 括号匹配问题,为什么一定要用栈来写?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) an
ACM 括号匹配问题,为什么一定要用栈来写?
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.
Sample Input
3
([])(([()])))([()[]()])()Sample Output
Yes
No
Yes
我是新人,打算定义四个变量K1K2K3K4,分别对应()【】,检测完一个字符串后比较K1是否等于K2,K3是否等于K4,同时前提条件是a【0】不等于】或者)
可是这样子提交上去就是运行错误.去看答案说是要用栈,我明白栈的原理可是这个方法不行吗?为何一定要用他?
ACM 括号匹配问题,为什么一定要用栈来写?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) an
用栈写比较简单呀,其他方法要考虑很多~你这种思路没考虑周全,反例一大堆.我随便举两个,如1、())( 2、()][