https://www.acmicpc.net/problem/1316
const fs = require("fs");
const file = process.platform === "linux" ? "/dev/stdin" : "./input.txt";
let input = fs.readFileSync(file).toString().split("\r\n");
let count = 0;
for (let i = 1; i <= input[0]; i++) {
let arr = [];
let string = input[i].split("");
for (let j = 0; j < string.length; j++) {
if (!arr.includes(string[j])) {
arr.push(string[j]);
}
if (string[j - 1] === string[j]) arr.push(string[j]);
}
if (arr.join("") === input[i]) count++;
}
console.log(count);
문제 풀이 강의
https://www.youtube.com/watch?v=btH6nvpvO2k
입력 받은 단어가 1개 또는 연속 중복 될때의 단어를 "그룹단어"라 칭한다.
즉, 'a', 'b' / 'aab', 'abbbcccc' 는 모두 다 "그룹단어"이다.
하지만, 'aba'와 같은 단어는 이미 나온 철자가 있으므로, "그룹단어"가 아니다.
split()
를 이용해 철자으로 쪼갠다.includes
를 사용하여 배열안에 쪼갠 철자의 유무를 판단 후 push
를 해주되, 배열에 이미 있는 철자라면 push
하지 않도록 한다.string[j - 1] === string[j]
)을 걸어 push
해준다.join()
메서드를 이용해 한 단어로 만든다. count
의 값을 올려준다.includes()