UVa-673 Parentheses Balance(栈模拟)
2017-08-29 22:12
435 查看
简单括号匹配问题
#include<iostream>
#include<cstring>
#include<stack>
#include<cstdio>
using namespace std;
stack<char> st;
char arr[130];
int main(){
int T;
cin>>T;
getchar();
while(T--){
while(st.size()) st.pop();
gets(arr);
int len = strlen(arr);
for(int i = 0; i<len; i++){
if(arr[i] == ' '){
continue;
}
if(st.size()){
if(st.top() == '(' && arr[i] == ')') st.pop();
else if(st.top() == '[' && arr[i] == ']') st.pop();
else st.push(arr[i]);
}
else st.push(arr[i]);
}
if(st.empty()) printf("Yes\n");
else printf("No\n");
}
return 0;
}
#include<iostream>
#include<cstring>
#include<stack>
#include<cstdio>
using namespace std;
stack<char> st;
char arr[130];
int main(){
int T;
cin>>T;
getchar();
while(T--){
while(st.size()) st.pop();
gets(arr);
int len = strlen(arr);
for(int i = 0; i<len; i++){
if(arr[i] == ' '){
continue;
}
if(st.size()){
if(st.top() == '(' && arr[i] == ')') st.pop();
else if(st.top() == '[' && arr[i] == ']') st.pop();
else st.push(arr[i]);
}
else st.push(arr[i]);
}
if(st.empty()) printf("Yes\n");
else printf("No\n");
}
return 0;
}
相关文章推荐
- UVa 673 - Parentheses Balance
- [UVa 673] 平衡的括号(Parentheses Balance)
- UVA 673 Parentheses Balance (栈)
- UVA673 Parentheses Balance【堆栈+输入流】
- UVa-673-Parentheses Balance
- uva 673 Parentheses Balance
- Parentheses Balance UVA 673
- UVa - 673 - Parentheses Balance(栈-stack)(Java和C++)
- UVa 673 - Parentheses Balance
- UVA - 673 Parentheses Balance
- UVa673 Parentheses Balance
- UVa-673-Parentheses Balance
- UVA 673 - Parentheses Balance
- Uva 673 - Parentheses Balance
- 【UVa 673】Parentheses Balance
- (平衡的括号)Parentheses Balance UVA - 673
- UVA - 673 - Parentheses Balance(栈)
- UVA 673 - Parentheses Balance
- UVa 673 - Parentheses Balance
- UVA - 673 Parentheses Balance