Jayden1116 2022. 5. 18. 14:55
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๊ฐ€ ์žˆ๋‹ค๋Š” ๊ฒƒ์„ ๊ผญ ๊ธฐ์–ตํ•˜์Ÿˆ ํ์–ด