解题思路:
注意事项:
参考代码:
import java.util.HashMap;
import java.util.Scanner;
public class Main {
static HashMap<String, Integer> map = new HashMap<String, Integer>();
static int judge(String str) {
if(map.containsKey(str)) return map.get(str);
if(str.indexOf("LOL") != -1) return -1;
if(str.length()<3||str.indexOf("*") == -1) return 0;
int res = -1;
char[] arr = str.toCharArray();
for (int i = 0; i < arr.length; i++) {
if(arr[i] == '*'){
arr[i] = 'L';
res = Math.max(res,-judge(new String(arr)));
if(res == 1) break;
else {
arr[i] = 'O';
res = Math.max(res,-judge(new String(arr)));
if(res == 1) break;
}
arr[i] = '*';
}
}
if(!map.containsKey(str)) map.put(str, res);
return res;
}
public static void main(String[] args) {
Scanner scaner = new Scanner(System.in);
int round = scaner.nextInt();
for (int i = 0; i < round; i++)
System.out.println(judge(scaner.next()));
scaner.close();
}
}
0.0分
1 人评分
C二级辅导-求偶数和 (C++代码)浏览:812 |
C二级辅导-等差数列 (C++代码)浏览:2309 |
C二级辅导-阶乘数列 (C语言代码)浏览:891 |
【蟠桃记】 (C语言代码)浏览:826 |
C语言程序设计教程(第三版)课后习题7.5 (C语言代码)浏览:640 |
C语言程序设计教程(第三版)课后习题7.4 (Java代码)浏览:873 |
简单的a+b (C语言代码)浏览:764 |
兰顿蚂蚁 (C++代码)浏览:1225 |
输出正反三角形 (C语言代码)浏览:859 |
C语言训练-求1+2!+3!+...+N!的和 (C语言代码)浏览:822 |