**The title of this question is too long, the title is behind the code**
answer
41
Precautions
-
Important: When the Scanner recognizes a space, it will be considered as the second input, and a for loop is needed to accept the input. If it is only received once, only the content before the first space will be received, such as:
-
When judging characters, the case of o
Problem solving ideas
Brute force cracks in 8 directions. After cracking one of the directions, the remaining seven are cracked in sequence using the same method.
Code
import java.util.Scanner;
public class Main {
//蓝桥杯要求class命名为Main,且无package
public static void main(String []args){
int length = 100; //定义该方阵的长
char a[][] = new char[length][length];
Scanner scanner = new Scanner(System.in);
String str[]=new String[length];
for(int i=0;i<length;i++){
str[i] = scanner.next(); //*** 重点:scanner识别到空格会认为是第二次输入!!
}
for(int i=0;i<length;i++){
//将字符串方阵转换为char方阵
for(int j=0;j<length;j++){
a[i][j] = str[i].charAt(j) ;
}
}
int count =0;
for(int i=0;i<length;i++){
//开始暴力破解8种方向,想通第一种,后七种就是愉快的'搬砖'
for(int j=0;j<length;j++){
if(j<length-6) //1横向
if(a[i][j]=='L')
if(a[i][j+1]=='A')
if(a[i][j+2]=='N')
if(a[i][j+3]=='Q')
if(a[i][j+4]=='I')
if(a[i][j+5]=='A')
if(a[i][j+6]=='O')
count++;
if(i<length-6) //2纵向
if(a[i][j]=='L')
if(a[i+1][j]=='A')
if(a[i+2][j]=='N')
if(a[i+3][j]=='Q')
if(a[i+4][j]=='I')
if(a[i+5][j]=='A')
if(a[i+6][j]=='O')
count++;
if(j>=6) //3反横向
if(a[i][j]=='L')
if(a[i][j-1]=='A')
if(a[i][j-2]=='N')
if(a[i][j-3]=='Q')
if(a[i][j-4]=='I')
if(a[i][j-5]=='A')
if(a[i][j-6]=='O')
count++;
if(i>=6) //4反纵向
if(a[i][j]=='L')
if(a[i-1][j]=='A')
if(a[i-2][j]=='N')
if(a[i-3][j]=='Q')
if(a[i-4][j]=='I')
if(a[i-5][j]=='A')
if(a[i-6][j]=='O')
count++;
if(i<length-6&&j<length-6) //5斜右下
if(a[i][j]=='L')
if(a[i+1][j+1]=='A')
if(a[i+2][j+2]=='N')
if(a[i+3][j+3]=='Q')
if(a[i+4][j+4]=='I')
if(a[i+5][j+5]=='A')
if(a[i+6][j+6]=='O')
count++;
if(i>=6&&j<length-6) //6斜右上
if(a[i][j]=='L')
if(a[i-1][j+1]=='A')
if(a[i-2][j+2]=='N')
if(a[i-3][j+3]=='Q')
if(a[i-4][j+4]=='I')
if(a[i-5][j+5]=='A')
if(a[i-6][j+6]=='O')
count++;
if(i>=6&&j>=6) //7斜左上
if(a[i][j]=='L')
if(a[i-1][j-1]=='A')
if(a[i-2][j-2]=='N')
if(a[i-3][j-3]=='Q')
if(a[i-4][j-4]=='I')
if(a[i-5][j-5]=='A')
if(a[i-6][j-6]=='O')
count++;
if(i<length-6&&j>=6) //8斜左下
if(a[i][j]=='L')
if(a[i+1][j-1]=='A')
if(a[i+2][j-2]=='N')
if(a[i+3][j-3]=='Q')
if(a[i+4][j-4]=='I')
if(a[i+5][j-5]=='A')
if(a[i+6][j-6]=='O')
count++;
}
}
System.out.println(count);
}
}
~
topic
Title: Letter Array
If you look carefully, you will find that in the 8x8 square matrix below, there is a sequence of letters: "LANQIAO" hidden. SLANQIAO ZOEXCCGB MOAYWKHI BCCIPLJQ SLANQIAO RSFWFNYA XIFZVWAL COAIQNAL We promise: The sequence can be horizontal, vertical, or oblique; and the direction is unlimited (in fact, there are a total of 8 directions). There are a total of 4 strings that meet the requirements in the above picture. There is a larger (100x100) square matrix of letters below. Can you figure out how many "LANQIAO" are hidden in it? FOAIQNALWIKEGNICJWAOSXDHTHZPOLGYELORAUHOHCZIERPTOOJUITQJCFNIYYQHSBEABBQZPNGYQTCLSKZFCYWDGOAIADKLSNGJ GSOZTQKCCSDWGUWAUOZKNILGVNLMCLXQVBJENIHIVLRPVVXXFTHQUXUAVZZOFFJHYLMGTLANQIAOQQILCDCJERJASNCTLYGRMHGF TSDFYTLVIBHKLJVVJUDMKGJZGNNSTPVLCKTOFMUEUFSVQIAUVHNVFTGBDDARPKYNNCUOYUAZXQJNOEEYKLFRMOEMHUKJTPETHLES FKVINSLWEVGAGMKVFVIUBMYOIAFHLVNKNTYKTZWVXQWRWIGPENFXYDTKRVPKRTHMGHVYOCLDCKMEKRLGEKBYUCLOLYPAKPFSOREH KWPUOLOVMOFBIXYACWRDYBINTMPASPCEOKHXQIGBQQMCEOIVULIEOPFSCSIHENAJCVDPJDOIWIIULFDNOZOFVAMCABVGKAKCOZMG XWMYRTAFGFOCNHLBGNGOXPJSTWLZUNNAGIRETGXFWAQSSJPFTQAXMTQWMZWYVEPQERKSWTSCHSQOOBGXAQTBCHOEGBDVKGWJIFTG ZWWJEIISPLMXIMGHOOGDRZFTGNDDWDWMNUFWJYJGULPHNUFSAQNNIUVAAFZIAZKFXXNWCEABGJAUMGYEIEFVQXVHHHEDYUITRCQB