SMALL

풀이
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));
const fs = require("fs");
const input = (
process.platform === "linux"
? fs.readFileSync("/dev/stdin").toString()
: `c=c=`
)
.trim()
.split("");
let croatiaWordCount = 0;
for (let i = 0; i < input.length; i++) {
let liftWord = input[i - 1];
let nowWord = input[i];
let rightWord = input[i + 1];
let rrWord = input[i + 2];
if (nowWord === "c") {
if (rightWord === "=" || rightWord === "-") {
croatiaWordCount++;
i++;
continue;
}
}
if (nowWord === "d") {
if (rightWord === "-") {
croatiaWordCount++;
i++;
continue;
}
if (rightWord === "z" && rrWord === "=") {
croatiaWordCount++;
i += 2;
continue;
}
}
if (nowWord === "l" || nowWord === "n") {
if (rightWord === "j") {
croatiaWordCount++;
i++;
continue;
}
}
if (nowWord === "s") {
if (rightWord === "=") {
croatiaWordCount++;
i++;
continue;
}
}
if (nowWord === "z") {
if (liftWord !== "d" && rightWord === "=") {
croatiaWordCount++;
i++;
continue;
}
}
croatiaWordCount++;
}
console.log(croatiaWordCount);LIST
'코테 > 코테withJS' 카테고리의 다른 글
| 백준 Node.js(자바스크립트) 1011문제 Fly me to the Alpha Centauri (0) | 2021.09.10 |
|---|---|
| 백준 Node.js(자바스크립트) 2839번 설탕배달 (0) | 2021.09.10 |
| 백준 Node.js(자바스크립트) 2869번 달팽이올라가는 문제 (0) | 2021.08.29 |
| 백준 Node.js(자바스크립트) 1712번 손익분기점 문제 (0) | 2021.08.20 |
| Node.js로 백준문제풀기 런타임에러(runtime error) (0) | 2021.08.06 |