tedted111   3년 전

#include

#include

#include

#define _CRT_SECURE_NO_WARNINGS

int main()

{

int L = 0; //세로

int W = 0; //가로

//블랙을 1 화이트가 0

scanf("%d %d", &L, &W);

char chess[50][50];

for (int i = 0; i < L; i++) {

scanf("%s", &chess[i]); //받어 체스판이 입력됨

}

char chess_white[50][50];

char chess_black[50][50];

for (int i = 0; i < 8; i++) {

for (int j = 0; j < 8; j++) {

if ((i % 2 == 0) && (j % 2 == 0))

chess_black[i][j] = 'B';

if ((i % 2 == 0) && (j % 2 != 0)) // 블랙으로 시작하는 체스판

chess_black[i][j] = 'W';

if ((i % 2 != 0) && (j % 2 != 0))

chess_black[i][j] = 'B';

if ((i % 2 != 0) && (j % 2 == 0))

chess_black[i][j] = 'W';

}

} // 블랙

for (int i = 0; i < 8; i++) {

for (int j = 0; j < 8; j++) {

if ((i % 2 == 0) && (j % 2 == 0))

chess_white[i][j] = 'W';

if ((i % 2 == 0) && (j % 2 != 0))

chess_white[i][j] = 'B'; //화이트로 시작하는 체스판

if ((i % 2 != 0) && (j % 2 != 0))

chess_white[i][j] = 'W';

if ((i % 2 != 0) && (j % 2 == 0))

chess_white[i][j] = 'B';

}

} //화이트

int check = 0;

int check1 = 0;

int big[100] = { 0 };

int m = 0;

int n = 0;

int h = 0;

for (int l = 0; l < L - 7; l++) { //세로로 1이동

for (int k = 0; k < W - 7; k++) { //가로로 1이동

check = 0;

check1 = 0;

for (int i = 0; i < 8; i++) {

n = 0;

for (int j = 0; j < 8; j++) {

if (chess[m + l][n + k] != chess_white[i][j]) // 비교하는거임 입련된 코드랑 기존의 코드랑

check += 1;

if (chess[m + l][n + k] != chess_black[i][j])

check1 += 1;

++n;

}

m++;

}

m = 0;

if (check > check1) {

big[h] = check1; // 한바퀴 돌고 나온후 블랙 화이트 체스판어느쪽이 낮은지 확인후 입력

}

else {

big[h] = check;

}

h++;

}

}

int ans = 2501;

for (int i = 0; i < h; i++) {

if (big[i] < ans) ans = big[i];

}

printf("%d\n", ans);

return 0;

}

댓글을 작성하려면 로그인해야 합니다.