Description now, there is a line of parentheses, please check that the brackets are paired. Enter the first line to enter a number n (0<n<=100) to indicate that there are N groups of test data. The next n rows are entered into multiple sets of input data, each set of input data is a string s (S is less than 10000, and S is not an empty string), and the number of test data sets is less than 5 groups. Data guarantee S contains only "[", "]", "(", ")" Four characters output
The output of each set of input data is one row, and if the parentheses contained in the string are paired, the output yes, and no if not paired
Sample input
3
[(])
(])
([[] ()])
Sample output
No
no
Yes
#include <stdio.h>
#include <string.h>
int main ()
{
int n,i,top;
scanf ("%d", &n);
GetChar ();
while (n--)
{
char s[10001],ch;
Top=-1;
while ((Ch=getchar ())!= ' \ n ')
{
if (ch== ') ' &&top>=0&&s[top]== ' (') //top>=0 ±íã÷õ»²»îª¿õ
top--;
else
if (ch== '] ' &&top>=0&&s[top]== ')
top--;
else
s[++top]=ch;
}
if (top==-1)
printf ("yes\n");
else
printf ("no\n");
}
return 0;
}
Bracket matching this problem in Nanyang OJ's official network, we can write their own code and then go to the above to submit a test, URL: Click to open the link