문제
https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV14QpAaAAwCFAYi
코드
import java.io.*;
class Solution {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
for(int test_case = 1; test_case <= 10; test_case++)
{
char board[][] = new char[8][8];
int n = Integer.parseInt(br.readLine());
for(int i = 0; i < 8; i++) {
String str = br.readLine();
for(int j = 0; j < 8; j++) {
board[i][j] = str.charAt(j);
}
}
int count = 0;
// 세로 회문 구하기
for(int i = 0; i <= 8 - n; i++) {
for(int j = 0; j < 8; j++) {
boolean check = true;
for(int k=0;k<n/2;k++) {
if(board[i+k][j] != board[i+n-1-k][j]) {
check = false;
break;
}
}
if(check) count++;
}
}
// 가로 회문 구하기
for(int i = 0; i < 8; i++) {
for(int j = 0; j <= 8 - n; j++) {
boolean check = true;
for(int k=0;k<n/2;k++) {
if(board[i][j+k] != board[i][j+n-1-k]) {
check = false;
break;
}
}
if(check) count++;
}
}
System.out.println("#"+test_case+" "+count);
}
}
}