P176 test 6-1 UVa673】的更多相关文章

//P176 test 6-1 #include<cstdio> #include<stack> #include<string> #include<iostream> using namespace std; int main(){ freopen("p.txt","r",stdin); freopen("pout.txt","w",stdout); string s; whi…
// UVa673 Parentheses Balance // 题意:输入一个包含()和[]的括号序列,判断是否合法. // 具体递归定义如下:1.空串合法:2.如果A和B都合法,则AB合法:3.如果A合法则(A)和[A]都合法. // 算法:用一个栈.注意输入可能有空串 #include<cstdio> #include<cstring> #include<iostream> #include<string> #include<algorithm&…
这三题比较简单,只放代码了. 题目:6-1 UVa673 - Parentheses Balance //UVa673 - Parentheses Balance //Accepted 0.000s //#define _XIENAOBAN_ #include<iostream> using namespace std; int N; char line[130]; bool st[130]; bool cal() { if (*line == '\0') return true; auto…
题意:1.空串合法.2.若A和B合法,则AB合法.3.若A合法,则(A)和[A]合法. 思路:遍历串,遇到(或[,则压入队列,若遇到),判断:若栈空,则不合法:若栈顶元素不是(,也不合法.]同理.因为判断的是栈顶元素,所以能成对的左括号都可及时弹出. 注意:1.用gets读,因空串合法.2.遍历后,栈不为空,也不合法. #include<iostream> #include<cstdio> #include<cstring> #include<string>…
如果是一个合法的序列,每对配对的括号的两个字符('(' 和 ')' 或者 '[' 和 ']')一定是相邻的,每次判断下该字符是否有配对即可. 如果配对,将左括号出栈即可.特别注意:空格也是合法的. AC代码: #include<cstdio> #include<stack> using namespace std; const int maxn = 200; char str[maxn]; stack<char>s; bool Balance(){ char ch; f…
简单栈题 #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]=='…
题目大意:给一个括号串,看是否匹配. 题目分析:一开始用区间DP写的,超时了... 注意:空串合法. 代码如下: # include<iostream> # include<cstdio> # include<stack> # include<cstring> # include<algorithm> using namespace std; char p[130]; stack<char>s; bool judge() { int…
分析:栈的应用,遇到右括号便弹出栈顶元素,看是否与右括号相互匹配,其余情况压入栈. 注意:本题有坑,空串空串,为此我跪了数次 #include<iostream> #include<string> #include<stack> using namespace std; int main() { int n; cin>>n; cin.get(); while(n--) { stack<char> s; string str; int flag=0…
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 括号匹配. 栈模拟就好. 多种括号也是一样可以做的. [代码] #include <bits/stdc++.h> using namespace std; const int N = 150; stack <char> sta; string s; int main() { #ifdef LOCAL_DEFINE freopen("F:\\c++source\\rush_in.txt", &qu…
<C++程序设计> 谭浩强  清华大学出版社 2016-08-03 1.P167 一般的C++编译系统为每个指针变量分配4个字节的存储单元,用来存放变量的地址. 2.P169 .cpp文件头 通常写法: #include <iostream> using namespace std; 说明:命名空间是C++的一种机制,C++的所有标识符都被定义在std命名空间中.使用std命名空间后,输入输出可以直接写成cout<<  与 cin>> 的形式:否则需写std…