蓝桥杯 18省赛 C3 字母阵列(找规律)
标题:字母阵列
仔细寻找,会发现:在下面的8x8的方阵中,隐藏着字母序列:“LANQIAO”。
SLANQIAO
ZOEXCCGB
MOAYWKHI
BCCIPLJQ
SLANQIAO
RSFWFNYA
XIFZVWAL
COAIQNAL
我们约定: 序列可以水平,垂直,或者是斜向;
并且走向不限(实际上就是有一共8种方向)。
上图中一共有4个满足要求的串。
下面有一个更大的(100x100)的字母方阵。
你能算出其中隐藏了多少个“LANQIAO”吗?
(数据太密集,还是不放上来了)
=========================
思路:
就是简单的找规律->100100矩阵中存在多少个77矩阵
public class 细节_3 {
static String[] s =new String[100];
public static void main(String[] args) {
init();
char[][] cha =new char[7][7];
int sum =0;
String str1 ="" ,str2 ="";
for(int i =0 ;i <94 ;i ++)
for(int j =0 ;j <94 ;j ++)
for(int k =0 ;k <7 ;k ++) {
cha[k] =s[i].substring(j, j +7).toCharArray();
for(int m =0 ;m <7 ;m ++) {
str1 =str2 ="";
for(int n =0 ;n <7 ;n ++) { str1 +=cha[m][n]; str2 +=cha[n][m]; }
if(str1.equals("LANQIAO") ||str1.equals("OAIQNAL")) { sum ++;}
if(str2.equals("LANQIAO") ||str2.equals("OAIQNAL")) { sum ++;}
}
str1 =cha[0][0]+""+cha[1][1]+""+cha[2][2]+""+cha[3][3]+""+cha[4][4]+""+cha[5][5]+""+cha[6][6];
str1 =cha[0][6]+""+cha[1][5]+""+cha[2][4]+""+cha[3][3]+""+cha[4][2]+""+cha[5][1]+""+cha[6][0];
if(str1.equals("LANQIAO") ||str1.equals("OAIQNAL")) { sum ++;}
if(str2.equals("LANQIAO") ||str2.equals("OAIQNAL")) { sum ++;}
}
System.out.println(sum);
}
private static void init() {
Scanner sc =new Scanner(System.in);
for(int i =0 ;i <100 ;i ++) s[i] =sc.nextLine();
sc.close();
}
}