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

[๋ฐฑ์ค€][Node.js] 5586๋ฒˆ : JOI์™€ IOI

by ๐Ÿ‡๋ฐ•๋ด‰๋ด‰๐Ÿ‡ 2021. 11. 26.

 

 

Algorithm

-  JOI์™€ IOI -

 


 

๋ฌธ์ œ

์ž…๋ ฅ์œผ๋กœ ์ฃผ์–ด์ง€๋Š” ๋ฌธ์ž์—ด์—์„œ ์—ฐ์†์œผ๋กœ 3๊ฐœ์˜ ๋ฌธ์ž๊ฐ€ JOI ๋˜๋Š” IOI์ธ ๊ณณ์ด ๊ฐ๊ฐ ๋ช‡ ๊ฐœ ์žˆ๋Š”์ง€ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. ๋ฌธ์ž์—ด์€ ์•ŒํŒŒ๋ฒณ ๋Œ€๋ฌธ์ž๋กœ๋งŒ ์ด๋ฃจ์–ด์ ธ ์žˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ์•„๋ž˜์™€ ๊ฐ™์ด "JOIOIOI"์—๋Š” JOI๊ฐ€ 1๊ฐœ, IOI๊ฐ€ 2๊ฐœ ์žˆ๋‹ค.

 

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

 

๋ฌธ์ œ ํ’€๊ธฐ

let fs = require("fs");
let input = fs.readFileSync("/dev/stdin").toString();
let joi = 0;
let ioi = 0;

for (let i = 0; i < input.length; i++) {
	if (input.slice(i, i + 3) === 'JOI') joi++;
	else if (input.slice(i, i + 3) === 'IOI') ioi++;
}

console.log(joi + '\n' + ioi);

 

 

 

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€