2차원 배열 저장 후 3중첩 for문 검사
import java.util.Scanner;
class Solution {
public static void main(String args[]) throws Exception {
Scanner sc = new Scanner(System.in);
for(int test_case = 1; test_case <= 10; test_case++) {
int n = sc.nextInt();
int count = 0;
char[][] board = new char[8][8];
for(int i = 0; i < 8; i++) {
board[i] = sc.next().toCharArray();
}
for(int l = 0; l < 8; l++) {
for(int k = 0; k <= 8 - n; k++) {
boolean[] palindrome = {true, true};
for(int h = 0; h < n/2; h++) {
if(board[l][k+h] != board[l][k-h+n-1]) {
palindrome[0] = false;
break;
}
}
for(int h = 0; h < n/2; h++) {
if(board[k+h][l] != board[k-h+n-1][l]) {
palindrome[1] = false;
break;
}
}
if(palindrome[0]) count++;
if(palindrome[1]) count++;
}
}
System.out.println("#" + test_case + " " + count);
}
}
}
for test_case in range(1, 10 + 1):
n = int(input())
board = [0] * 8
for i in range(8):
board[i] = list(input())
count = 0
for l in range(8):
for k in range(9-n):
palindrome = [True, True]
for h in range(n//2):
if board[l][k+h] != board[l][k-h+n-1]:
palindrome[0] = False
break
for h in range(n//2):
if board[k+h][l] != board[k-h+n-1][l]:
palindrome[1] = False
break
if palindrome[0]:
count += 1
if palindrome[1]:
count += 1
print("#", test_case, " ", count, sep="")