参考代码:
import java.util.Scanner; public class Main { static String in; static int index = -1; public static void main(String[] args) { Scanner scanner = new Scanner(System.in); in = scanner.next(); System.out.print(dfs()); } public static int dfs() { int max = 0; int current = 0; while(index < in.length() - 1) { index++; if(in.charAt(index) == 'x') current++; else if(in.charAt(index) == '(') current += dfs(); else if(in.charAt(index) == ')') break; else if(in.charAt(index) == '|') { max = Math.max(current, max); current = 0; } } return Math.max(max, current); } }
0.0分
5 人评分