括号匹配
package luyunzhou.one;
import java.util.Scanner;
import java.util.Stack;
public class Parentheses {
public static void main(String[] args) {
// TODO Auto-generated method stub
Stack<Character> sta = new Stack<Character>();
Scanner scanner = new Scanner(System.in);
String a = scanner.nextLine();
char[] b = a.toCharArray();
boolean flag = false;
for (int i = 0; i < b.length; i++) {
if(b[i]=='['||b[i]=='{'||b[i]=='(')
sta.push(b[i]);
else {
if(b[i]==']'&&(sta.pop()=='[')||b[i]=='}'&&(sta.pop()=='{')||b[i]==')'&&(sta.pop()=='('))
flag = true;
else{
flag = false;
break;
}
}
}
System.out.println(flag);
}
}