회문(回文, palindrome) : "기러기", "토마토", "스위스"와 같이 똑바로 읽어도 거꾸로 읽어도 똑같은 문장이나 낱말
예시 :

위 그림에서 회문 4개를 찾음
import java.util.Scanner;
import java.io.FileInputStream;
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 answer = 0;
char[][] palindrome = new char[8][8];
for (int i=0; i<8; i++) {
String a = sc.next();
for(int j=0; j<8; j++) {
palindrome[i][j] = a.charAt(j);
}
}
int a=0;
int b=0;
for(int y=0; y<8; y++) {
for (int i = 0; i < (8 - N + 1); i++) {
for (int j = 0; j < (N / 2); j++) {
if (palindrome[y][i+j] == palindrome[y][i + N -1 -j]) a++;
if (palindrome[i+j][y] == palindrome[i + N -1 -j][y]) b++;
}
if(a == N / 2) answer++; a=0;
if(b == N / 2) answer++; b=0;
}
}
System.out.println("#" + test_case + " " + answer);
}
}
}

import java.util.HashMap;
import java.util.Scanner;
import java.io.FileInputStream;
/*
사용하는 클래스명이 Solution 이어야 하므로, 가급적 Solution.java 를 사용할 것을 권장합니다.
이러한 상황에서도 동일하게 java Solution 명령으로 프로그램을 수행해볼 수 있습니다.
*/
class Solution
{
public static void main(String args[]) throws Exception
{
Scanner sc = new Scanner(System.in);
int T;
T=10;
for(int test_case = 1; test_case <= T; test_case++)
{
int N = sc.nextInt();
String a;
char[][] arr = new char[8][8];
for(int i=0; i<8; i++) {
a = sc.next();
for(int j=0; j<8; j++) {
arr[i][j] = a.charAt(j);
}
}
int answer = 0;
boolean cca = true;
boolean ccb = true;
for (int i = 0; i < 8; i++) {
for(int j=0; j<=8-N; j++) {
for(int x=0; x<N/2; x++) {
if (arr[i][j+x] != arr[i][j+N-1-x]) {
cca = false;
}
if(arr[j+x][i] != arr[j+N-1-x][i]) {
ccb = false;
}
}
if(cca) answer++;
if(ccb) answer++;
cca = true;
ccb = true;
}
}
System.out.println("#"+test_case+" "+answer);
}
}
}
