Parentheses Balance(括号匹配)--栈
来源:互联网 发布:js垂直轮播广告幻灯片 编辑:程序博客网 时间:2024/06/06 02:36
/*******************************************************************************************************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.
Input
The file contains a positive integer n and a sequence of n strings of parentheses () and [], one string a line.
Output
A sequence of Yes or No on the output file.
Sample Input
3([])(([()])))([()[]()])()
Sample Output
YesNoYes*******************************************************************************************************************/
#include<stdio.h>
#include<string.h>int main()
{
char q[300],w[300];
int n,j,k,i;
scanf("%d%*c",&n);
for(i=0;i<n;i++)
{
memset(q,0,sizeof(q));
gets(q);
int len=strlen(q);
for(k=0,j=0;j<len;j++)
{
if((q[j]==')' && w[k-1]=='(') || (q[j]==']' && w[k-1]=='['))
{
k--;
}
else
{
w[k]=q[j];
k++;
}
}
if(k==0)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
0 0
- Parentheses Balance(括号匹配)--栈
- 模拟,括号匹配——Parentheses Balance
- UVA 673 Parentheses Balance(括号匹配)
- Parentheses Balance——括号匹配
- UVa 673 Parentheses Balance(括号配对 栈)
- Uva673 Parentheses Balance(栈)
- [UVa 673] 平衡的括号(Parentheses Balance)
- Valid Parentheses(用栈实现括号匹配)
- LeetCode 20 Valid Parentheses(用栈判断括号匹配)
- 【栈操作&括号匹配】Valid Parentheses
- Generate Parentheses--生成匹配括号(重)
- LeetCode | Valid Parentheses(括号匹配)
- 20. Valid Parentheses (括号匹配)
- Valid Parentheses --括号匹配
- Valid Parentheses:括号匹配
- Uva 673 Parentheses Balance 平衡的括号
- 平衡的括号(Parentheses Balance,UVa 673)
- UVa 673 Parentheses Balance 平衡的括号
- lucene索引结构(三)-词项向量(TermVector)索引文件结构分析
- C++库常用函数一览
- Android 短彩信数据模型介绍
- table边框
- windows中使用Git工具连接GitHub(配置篇)
- Parentheses Balance(括号匹配)--栈
- 最大子矩阵和问题
- 003
- IOS7.1下载企业版应用报“xxx证书无效”的解决方案
- Week 1
- 进程间通信-信号量
- codeforces237C Primes on Interval
- Using DLP tools for cloud computing security
- 扑克牌顺子问题