let fs = require('fs');
let path = process.platform === 'linux' ? '/dev/stdin' : './data.txt';
let input = fs.readFileSync(path).toString().trim();
function solve(input) {
let croatia = new Array('c=', 'c-', 'dz=', 'd-', 'lj', 'nj', 's=', 'z=');
for (i = 0; i < croatia.length; i++) {
while (input.includes(croatia[i])) {
input = input.replace(croatia[i], 1);
}
}
return input.length;
}
console.log(solve(input));
const fs = require("fs");
const input = (
process.platform === "linux"
? fs.readFileSync("/dev/stdin").toString()
: `ljes=njak`
).trim();
let croatia = ["c=", "c-", "dz=", "d-", "lj", "nj", "s=", "z="];
function solution(input) {
for (let alphabet of croatia) {
input = input.split(alphabet).join("Q");
}
return input.length; // return input์ผ ๊ฒฝ์ฐ QeQQak๋ฅผ ๋ฐํํ๋ค.
}
console.log(solution(input));
replace๊ฐ ๋ฌธ์์ด ๋ด์ ํด๋นํ๋ ๋ชจ๋ value๋ฅผ ๋ฐ๊ฟ์ฃผ๋ ์ค ์๊ณ while์ if๋ก ํ๋ค๊ฐ ํ๋ฒ์ 1๊ฐ๋ง ๋ฐ๋๋ ๊ฒ์ ์๊ฒ ๋์๊ณ
if๋ฅผ while๋ก ์์ ํด์ ๊ณ์ ๋ฐ๋ณตํ๊ฒ๋ ํด์ฃผ์๋ค.
๋ํ, ๋ค๋ฅธ ํ์ด์ ๊ฒฝ์ฐ ๋ด๊ฐ ํผ ๋ฐฉ๋ฒ๊ณผ ๊ฐ์ ์์ด๋์ด์ง๋ง ๋ฐ๋ณต๋ฌธ์์ of๋ฅผ ์ฌ์ฉํ ์ !!!
python์์ ํน์ ๋ฐฐ์ด ๋ด์ ๊ฐ๋ค์ ๋ํ ๋ฐ๋ณต๋ฌธ์ ์์ฑํ ๋, in ์ ์ผ๋ ๊ฒ๊ณผ ๊ฐ์ด javascript์๋ of๊ฐ ์๋ค๋ ๊ฒ์ ๊ผญ ๊ธฐ์ตํ์ ํ์ด
'๐ JavaScript > ๋ฐฑ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[JS] 1712 (0) | 2022.05.18 |
---|---|
[JS] 1316 (0) | 2022.05.18 |
[JS] 5622 (0) | 2022.05.18 |
[JS] 2908 (0) | 2022.05.18 |
[JS] 1152 (0) | 2022.05.17 |