1018번: 체스판 다시 칠하기
#include <stdio.h>
int main(int argc, const char * argv[]) {
int M, N;
int rnum=2500;
scanf("%d %d", &M, &N);
char board[M][N+1];
for(int i=0; i<M; i++)
scanf("%s", board[i]);
// borad 판 생성, 입력 완료!!!
for(int stepy = 0; stepy < (M-7); stepy++) { // stepx, stepy의 좌표는 8*8 보드의 첫 시작점
for(int stepx = 0; stepx < (N-7); stepx++) {
int bcount = 0; // 첫블럭이 B일때 바꿔야 하는 수
int wcount = 0; // 첫블럭이 W일때 바꿔야 하는 수
int count;
// 검사
for(int i=0; i<8; i++) { // i는 세로, j는 가로
for(int j=0; j<8; j++) {
//첫 블럭이랑 색이 같은 것들 (홀수줄에 홀수 번째 칸, 짝수줄에 짝수번째 칸)
if((i%2 == 0 && j%2 == 0) || (i%2 == 1 && j%2 == 1)) {
if(board[stepy+i][stepx+j] == 'B') // 그 칸이 B라면
wcount++;
else if(board[stepy+i][stepx+j] == 'W')// 그 칸이 W라면
bcount++;
}else{ // 그 외
if(board[stepy+i][stepx+j] == 'B') // 그 칸이 B라면
bcount++;
else if(board[stepy+i][stepx+j] == 'W')// 그 칸이 W라면
wcount++;
}
}
}
if(bcount > wcount)
count = wcount;
else
count = bcount;
if(count < rnum)
rnum = count;
}
}
printf("%d\n", rnum);
return 0;
}