栈括号匹配!
import java.util.Scanner;
import java.util.Stack;
public class stack {
public static void main(String[] args) {
Stack a=new Stack();
Stack b=new Stack();
Stack c=new Stack();
int num;
Scanner cin = new Scanner(System.in);
num=cin.nextInt();
String test;
for (int i = 0; i < num; i++) {
test=cin.next();
for (int j = 0; j < test.length(); j++) {
char ll=test.charAt(j);
if(ll==’(’)
{
a.push(ll);
}
if(ll==’)’&&!a.isEmpty())
{
a.pop();
}
if(ll==’[’)
{
b.push(ll);
}
if(ll==’]’&&!b.isEmpty())
{
b.pop();
}
if(ll==’{’)
{
c.push(ll);
}
if(ll==’}’&&!c.isEmpty())
{
c.pop();
}
}
if(a.isEmpty()&&c.isEmpty()&&b.isEmpty())
System.out.println(“匹配”);
else
System.out.println(“不匹配”);
}
}
}