๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๊ฐœ์ธ๊ณต๋ถ€/Algorithm

[๋ฐฑ์ค€][Node.js] 8958๋ฒˆ : OXํ€ด์ฆˆ

by ๐Ÿ‡๋ฐ•๋ด‰๋ด‰๐Ÿ‡ 2021. 12. 15.

 

 

Algorithm

-  OXํ€ด์ฆˆ -

 


 

๋ฌธ์ œ

"OOXXOXXOOO"์™€ ๊ฐ™์€ OXํ€ด์ฆˆ์˜ ๊ฒฐ๊ณผ๊ฐ€ ์žˆ๋‹ค. O๋Š” ๋ฌธ์ œ๋ฅผ ๋งž์€ ๊ฒƒ์ด๊ณ , X๋Š” ๋ฌธ์ œ๋ฅผ ํ‹€๋ฆฐ ๊ฒƒ์ด๋‹ค. ๋ฌธ์ œ๋ฅผ ๋งž์€ ๊ฒฝ์šฐ ๊ทธ ๋ฌธ์ œ์˜ ์ ์ˆ˜๋Š” ๊ทธ ๋ฌธ์ œ๊นŒ์ง€ ์—ฐ์†๋œ O์˜ ๊ฐœ์ˆ˜๊ฐ€ ๋œ๋‹ค.

์˜ˆ๋ฅผ ๋“ค์–ด, 10๋ฒˆ ๋ฌธ์ œ์˜ ์ ์ˆ˜๋Š” 3์ด ๋œ๋‹ค.

 

"OOXXOXXOOO"์˜ ์ ์ˆ˜๋Š” 1+2+0+0+1+0+0+1+2+3 = 10์ ์ด๋‹ค.

 

OXํ€ด์ฆˆ์˜ ๊ฒฐ๊ณผ๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ, ์ ์ˆ˜๋ฅผ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

 

์ž…์ถœ๋ ฅ ์˜ˆ์‹œ

 

๋ฌธ์ œ ํ’€๊ธฐ

let fs = require("fs");
let input = fs.readFileSync("/dev/stdin").toString().trim().split("\n");

for (let i = 1; i <= Number(input[0]); i++) {
	let result = 0;
	let grade = 0;
	for (let j = 0; j < input[i].length; j++) {
		if (input[i][j] === "O") {
			grade++;
		} else if (input[i][j] === "X") {
			grade = 0;
		}
		result += grade;
	}
	console.log(result);
}

 

 

 

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€