Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | |||||
| 3 | 4 | 5 | 6 | 7 | 8 | 9 |
| 10 | 11 | 12 | 13 | 14 | 15 | 16 |
| 17 | 18 | 19 | 20 | 21 | 22 | 23 |
| 24 | 25 | 26 | 27 | 28 | 29 | 30 |
| 31 |
Tags
- BFS
- COS PRO
- 자바
- math
- 문제풀이
- binary search
- 이분탐색
- 코테
- db
- Java
- 투포인터
- 운동기록
- SWEA
- 문자열
- greedy
- MySQL
- priorityqueue
- 알고리즘
- 문제해결
- 시뮬레이션
- DP
- 코딩테스트
- BOJ
- 건강
- SQL
- 백준
- oracle
- dfs
- 러닝일지
- 프로그래머스
Archives
- Today
- Total
슈콩
[SWEA] 3일차 - 회문 1 본문


[문제]
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 |