JavaScript 백준 온라인 알고리즘 공부
백준 8958 번 JavaScript 문제
const fs = require("fs");
const [...arr] = (process.platform === "linux"
? fs.readFileSync("/dev/stdin").toString()
: `5
OOXXOXXOOO
OOXXOOXXOO
OXOXOXOXOXOXOX
OOOOOOOOOO
OOOOXOOOOXOOOOX
`
)
.trim()
.split("\n");
let nNumber = Number(arr[0]);
let answer = "";
for (let i = 1; i <= nNumber; i++) {
let count = 0;
let sum = 0;
for (let j = 0; j < arr[i].length; j++) {
arr[i][j] === "O" ? count++ : (count = 0);
sum += count;
}
answer += sum + "\n";
}
console.log(answer);