티스토리 뷰

https://www.acmicpc.net/problem/6186

 

6186번: Best Grass

Bessie is planning her day of munching tender spring grass and is gazing out upon the pasture which Farmer John has so lovingly partitioned into a grid with R (1 <= R <= 100) rows and C (1 <= C <= 100) columns. She wishes to count the number of grass clump

www.acmicpc.net

const fs = require('fs');
const [n, ...arr] = fs.readFileSync("./dev/stdin").toString().trim().split("\n");

const [R, C] = n.split(' ').map(v => +v);
const board = arr.map(v => [...v.split(''), '.'])
board.push(new Array(C + 1).fill('.'));
let cnt = 0;
for (let i = 0; i < R; i++) {
  for (let j = 0; j < C; j++) {
    if (board[i][j] == '#') {
      cnt++;
      if (board[i + 1][j] == '#') {
        board[i + 1][j] = '.'
      }
      if (board[i][j + 1] == '#') {
        board[i][j + 1] = '.'
      }

    }
  }
}
console.log(cnt)
728x90
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/09   »
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
글 보관함