슈콩

[SWEA] 3일차 - 회문 1 본문

Algorithms/SWEA

[SWEA] 3일차 - 회문 1

shukong 2025. 11. 4. 00:07

 

 

[문제]

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV14QpAaAAwCFAYi

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

 

 

 

[소스  코드]

import java.util.*;
import java.io.*;
public class Solution {
	static int n;
	static char[][] map;
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		for(int tc=1;tc<=10;tc++) {
			n = Integer.parseInt(br.readLine());
			map = new char[8][8];
			for(int i=0;i<8;i++) {
				String s = br.readLine();
				for(int j=0;j<8;j++) {
					map[i][j] = s.charAt(j);
				}
			}
			int result = 0;
			for(int i=0;i<8;i++) {
				for(int j=0;j<8;j++) {
					if(canRow(i,j)) result++;
					if(canCol(i,j)) result++;
				}
			}
			System.out.println("#"+tc+" "+result);
		}
	}
	private static boolean canRow(int i,int j) {
		if(j>8-n) return false;
		for(int c=0;c<n/2;c++) {
			if(map[i][j+c]!=map[i][j+n-1-c]) return false;
		}
		return true;
	}
	private static boolean canCol(int i,int j) {
		if(i>8-n) return false;
		for(int r=0;r<n/2;r++) {
			if(map[i+r][j]!=map[i+n-1-r][j]) return false;
		}
		return true;
	}
}

'Algorithms > SWEA' 카테고리의 다른 글

[SWEA] 부분 수열의 합  (0) 2025.11.04
[SWEA] 5일차 - Magnetic  (0) 2025.11.04
[SWEA] 농작물 수확하기  (0) 2025.11.03
[SWEA] N-Queen  (0) 2025.10.30
[SWEA] 1일차 - Flattern  (0) 2025.10.30