UVa 673 平衡的括号】的更多相关文章

题意:给出包含"()"和"[]"的括号序列,判断是否合法. 用栈来完成,注意空串就行. #include<iostream> #include<string> #include<cstring> #include<stack> using namespace std; stack<char> sta; string s; int solve() { char str; ] == ; else { int l…
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==')')…
题目描述: 原题:https://vjudge.net/problem/UVA-673 题目思路: 1.水题 2.栈+模拟 3.坑在有空串 AC代码 #include <iostream> #include <stack> using namespace std; int main(int argc, char *argv[]) { int t; scanf("%d",&t); getchar(); while(t--) { string buf; st…
本来是当做水题来做的,后来发现这道题略坑. 首先输入的字符串可能是空串,所以我用了gets函数,紧接着就被scanf("%d", &n)后面的换行符坑掉了. 于是乎再加一句getchar() #include <cstdio> #include <stack> #include <cstring> using namespace std; ; char s[maxn]; bool ok(const char& c1, const ch…
 栈 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,…
 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…
题意描述: 给出一段只包含()和[]的字符串,判断是否合法,合法输出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…
题意:输入一个包含"()"和"[]"的序列,判断是否合法 用栈来模拟,遇到"(",“[”就入栈,遇到')',']'就取出栈顶元素看是否匹配,如果不匹配,则不合法 还有注意一下每次取出栈顶元素的时候判断栈是否为空,如果为空就要跳出循环 注意空串也是合法的串 #include<iostream> #include<cstdio> #include<cstring> #include <cmath> #i…
简单栈题 #include<bits/stdc++.h> using namespace std; int main() { int cas;cin>>cas;getchar(); string ss; while(cas--) { stack<char>s;char ch; getline(cin,ss);; ;i<ss.size();i++) { // printf("%c ",ss[i]); if(ss[i]=='('||ss[i]=='…