AOJ : 1173 - 世界の天秤 (The Balance of the World)
問題概要
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1173&lang=jp
日本語問題文があるので, 説明省略です
アルゴリズム
とりあえず, アルファベットと空白とピリオドを全て消します.
あとは, "[]" と "()" を消せるだけ消します.
消しきったあと, 空文字列になったらyes, そうでなければno.
プログラム
Scanner sc = new Scanner(System.in); while(true){ String s = sc.nextLine(); if(s.equals(".")) break; s = s.replaceAll("[a-zA-Z \\.]",""); while(!s.equals("")){ String before = s; s = s.replaceAll("\\(\\)|\\[\\]",""); if(before.equals(s)) break; } System.out.println(s.equals("") ? "yes" : "no"); }