【习题 6-1 UVA-673】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…
一个匹配左右括号的问题 /*UVa 673 Parentheses Balance*/ #include<iostream> #include<algorithm> #include<cmath> #include<cstring> #include<stack> using namespace std; char c[500]; int n; int pd(char q,char e){ if(q=='(' && e==')')…
 栈 Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu   Description 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,…
题意:输入一个包含"()"和"[]"的序列,判断是否合法 用栈来模拟,遇到"(",“[”就入栈,遇到')',']'就取出栈顶元素看是否匹配,如果不匹配,则不合法 还有注意一下每次取出栈顶元素的时候判断栈是否为空,如果为空就要跳出循环 注意空串也是合法的串 #include<iostream> #include<cstdio> #include<cstring> #include <cmath> #i…
题意描述: 给出一段只包含()和[]的字符串,判断是否合法,合法输出YES,不合法输出NO 规则: 1.该串为空,则合法 2.若A合法,B合法,则AB合法 3.若A合法,则(A)和[A]均合法 解题思路: 括号匹配问题,使用栈来解决,需要注意的是用gets来读取,当该串为空时,输出YES 代码实现: #include<stdio.h> #include<string.h> int f(char a[],int l); int main() { ]; int T; scanf(&qu…
题目描述 : 判断字符串是不是符合正确的表达式形式. 要点 : 考虑字符串为空的时候,用getline输入,每一次判断后如果为No则要清空栈.对称思想. 注意输入格式. 代码: #include <iostream> #include <string> #include <cstdio> #include <cstring> #include <algorithm> #include <stack> using namespace s…
题目 题目     分析 写了个平淡无奇的栈处理表达式,在WA了5发后发现,我没处理空串,,,,(或者说鲁棒性差?     代码 #include <bits/stdc++.h> using namespace std; bool equal(char a,char b) { if((a=='(' && b==')') || (a=='[' && b==']')) return true; return false; } int main() { int len…
// UVa673 Parentheses Balance // 题意:输入一个包含()和[]的括号序列,判断是否合法. // 具体递归定义如下:1.空串合法:2.如果A和B都合法,则AB合法:3.如果A合法则(A)和[A]都合法. // 算法:用一个栈.注意输入可能有空串 #include<cstdio> #include<cstring> #include<iostream> #include<string> #include<algorithm&…
 Parentheses Balance  You are given a string consisting of parentheses () and []. Astring 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. Writ…
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 take…