본문 바로가기
Algorithm

[백준 알고리즘] 1316번: 그룹 단어 체커 (JavaScript - 실패코드)

by Baest 2022. 1. 16.

[문제]

 

 

 

[제출한 코드]

 

- JavaScript 

// 실패코드 (aa 가 중복된 것에 대한 처리가 안됐음)

const fs = require('fs');
const input = fs.readFileSync('in_progress/ex.txt').toString().split('\n');
const Cnt = Number(input[0]);

//console.log(Cnt) 
//console.log(input[1], input[2], input[3])
let SeriseCnt = 0;

for (let i = 1; i <= Cnt; i++) { 
    const array = [];
    const word = input[i];
    console.log(word)
    let groupWord = true;

    for (let j = 0; j < word.length; j++) { 
        console.log("word.length: " + word.length) // '/r'

        let firstIdx = array.indexOf(word[j]); // 
        let LastIdx = array.lastIndexOf(word[j]);

        if (firstIdx === LastIdx) {
            // console.log("===========" + firstIdx )
            array.push(word[j]);
            console.log("array: " + array)
        } else { 
            if (firstIdx !== LastIdx) {  
                groupWord = false;
                break;
            }
        }
    }
    if (groupWord) { 
        SeriseCnt += 1;
    }

}

console.log("SeriseCnt " + SeriseCnt);

 

 

- Python

 

 

 

문제 링크: https://www.acmicpc.net/problem/1316

 

1316번: 그룹 단어 체커

그룹 단어란 단어에 존재하는 모든 문자에 대해서, 각 문자가 연속해서 나타나는 경우만을 말한다. 예를 들면, ccazzzzbb는 c, a, z, b가 모두 연속해서 나타나고, kin도 k, i, n이 연속해서 나타나기 때

www.acmicpc.net