풀이
KeyPoint
원래 말의 수 - 입력받은 말의 수 = 필요한 말의 수
map()
join()
- 체스 배열(chess)을 만든다.
- 입력받은 값을 순회(map)한다.
- chess[index] - num (=== 필요한 말의 수) 를 반환하여 result 배열을 만든다.
- 만들어진 result 배열을 join(" ")으로 공백을 두며 문자열로 합친다.
코드
const input = require("fs").readFileSync("/dev/stdin").toString().split(" ");
const chess = [1, 1, 2, 2, 2, 8];
const result = input.map((num, index) => {
return chess[index] - Number(num);
});
console.log(result.join(" "));
'Programing > 백준' 카테고리의 다른 글
[백준/JS] 10988 - 팰린드롬인지 확인하기 (0) | 2023.09.06 |
---|---|
[백준/JS] 2444 - 별 찍기 - 7 (0) | 2023.09.04 |
[백준/JS] 11718 - 그대로 출력하기 (0) | 2023.08.30 |
[백준/JS] 5622 - 다이얼 (0) | 2023.08.29 |
[백준/JS] 2908 - 상수 (0) | 2023.08.28 |
댓글