uva673 Parentheses Balance

简介: uva673 Parentheses Balance
#include <stdio.h>#include <string.h>#define LOCALcharstr[130];
charstack[130];
intmain()
{
inti, j, n;
intlen;
inttop;
#ifndef LOCALfreopen("c://uva_in.txt", "r", stdin);
#endifscanf("%d", &n);
getchar();
for (i=0; i<n; i++)
    {
gets(str);
len=strlen(str);
if (len==0)
        {
printf("Yes/n");
continue;
        }
stack[0] =str[0];
top=0;
for (j=1; j<len; j++)
        {
if (str[j] =='('||str[j] =='[')
stack[++top] =str[j];
elseif (str[j] ==')')
            {
if (top>=0&&stack[top] =='(')
--top;
elsestack[++top] =str[j];
            } else            {
if (top>=0&&stack[top] =='[')
--top;
elsestack[++top] ==str[j];
            }
        }
if (top==-1)
printf("Yes/n");
elseprintf("No/n");
    }
return0;
}
目录
相关文章
|
7月前
|
Java
hdu-1016-Prime Ring Problem
hdu-1016-Prime Ring Problem
31 0
UVa1531 - Problem Bee
UVa1531 - Problem Bee
56 0
uva101 The Blocks Problem
uva101 The Blocks Problem
58 0
uva10035 Primary Arithmetic
uva10035 Primary Arithmetic
32 0
|
机器学习/深度学习
|
机器学习/深度学习 人工智能