본문 바로가기
코딩테스트/백준

1100. 하얀 칸 - Node.js

by MiteDev 2024. 9. 14.

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

 

const fs = require('fs');
const file_path = process.platform === 'linux' ? 'dev/stdin' : `${__dirname}/input.txt`
const input = fs.readFileSync(file_path).toString().trim().replace(/\r/g, '').split('\n');

/**
 * @param {string[]} input 
 * @returns 
 */
const solution = (input) => {
    const line_odd = [0, 2, 4, 6];
    const line_even = [1, 3, 5, 7];
    
    const result = input.flatMap((line, i) =>
        line_odd.includes(i) ? 
            line_odd.filter(el => line[el] === 'F') : line_even.filter(el => line[el] === 'F')
        ).length;

    return result;
}

console.log(solution(input));

 

 

'코딩테스트 > 백준' 카테고리의 다른 글

1159. 농구 경기 - Node.js  (1) 2024.09.14
1152. 단어의 개수 - Node.js  (0) 2024.09.14
1076. 저항 - Node.js  (1) 2024.09.12
1075. 나누기 - Node.js  (0) 2024.09.12
1009. 분산처리 - Node.js  (0) 2024.09.12