📄 3436127_ac_313ms_2152k.java
字号:
import java.util.*;
public class Main
{
private Scanner in;
private String str;
private int length;
private int [][] isSlump;
private int [][] isSlimp;
private boolean isSlumpString(int from, int to)
{
if (isSlump[from][to] != 0)
{
return isSlump[from][to] == 1;
}
if (str.charAt(from) != 'E' && str.charAt(from) != 'D')
{
isSlump[from][to] = -1;
return false;
}
int i = from + 1;
while (i < to && str.charAt(i) == 'F')
{
i++;
}
if (i == to || i == from + 1)
{
isSlump[from][to] = -1;
return false;
}
if (str.substring(i, to).equals("G") || isSlumpString(i, to))
{
isSlump[from][to] = 1;
return true;
}
isSlump[from][to] = -1;
return false;
}
private boolean isSlimpString(int from, int to)
{
if (isSlimp[from][to] != 0)
{
return isSlimp[from][to] == 1;
}
if (str.charAt(from) != 'A' || from == to - 1)
{
isSlimp[from][to] = -1;
return false;
}
if (to == from + 2)
{
if (str.charAt(to - 1) == 'H')
{
isSlimp[from][to] = 1;
return true;
}
isSlimp[from][to] = -1;
return false;
}
if (str.charAt(to - 1) != 'C')
{
isSlimp[from][to] = -1;
return false;
}
if (isSlumpString(from + 1, to - 1) || (str.charAt(from + 1) == 'B' && isSlimpString(from + 2, to - 1)))
{
isSlimp[from][to] = 1;
return true;
}
isSlimp[from][to] = -1;
return false;
}
public static void main(String [] args)
{
try
{
new Main().run();
}
catch (Exception e)
{
while (true)
{
System.out.println("I love Shengqi");
}
}
}
private void run() throws Exception
{
Scanner in = new Scanner (System.in);
int n;
boolean isSlurpy;
if (!in.hasNext())
{
throw new Exception("Empty Input");
}
n = in.nextInt();
System.out.println("SLURPYS OUTPUT");
while (n-- > 0)
{
str = in.next();
isSlurpy = false;
length = str.length();
isSlimp = new int [length + 1][length + 1];
isSlump = new int [length + 1][length + 1];
for (int i = 1; i < length; i++)
{
if (isSlimpString(0, i) && isSlumpString(i, length))
{
isSlurpy = true;
break;
}
}
System.out.println(isSlurpy ? "YES" : "NO");
}
System.out.println("END OF OUTPUT");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -