Skip to content

Commit f6507fa

Browse files
Merge pull request #739 from eric-hjh/main
[황장현] 120차 라이브 코테 제출
2 parents 276bb25 + a9af67c commit f6507fa

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const input = require('fs')
2+
.readFileSync(process.platform === 'linux' ? '/dev/stdin' : './input.txt')
3+
.toString()
4+
.trim()
5+
.split('\n');
6+
7+
const [N, M, K] = input[0].split(' ').map(Number);
8+
const board = input.slice(1).map((el) => el[0].split(''));
9+
10+
const sumB = Array.from({ length: N }, () => Array(M).fill(0));
11+
const sumW = Array.from({ length: N }, () => Array(M).fill(0));
12+
console.log(sumB);
13+
14+
function calculateSum(board, sum, start) {
15+
for (let i = 0; i < board.length; i++) {
16+
for (let j = 0; j < board[i].length; j++) {
17+
let count = 0;
18+
if ((i + j) % 2 === 0) {
19+
count = board[i][j] === start ? 1 : 0;
20+
} else {
21+
count = board[i][j] === start ? 0 : 1;
22+
}
23+
sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + count;
24+
}
25+
}
26+
}
27+
28+
calculateSum(board, sumB, 'B');
29+
calculateSum(board, sumW, 'W');

0 commit comments

Comments
 (0)