[백준 1343번] 그리디 알고리즘 - 폴리노미노

김민지·2023년 7월 19일
0

냅다 시작 백준

목록 보기
61/118

✨ 문제 ✨


✨ 정답 ✨

const { count } = require("console");
const fs = require("fs");
const { nextTick } = require("process");
const filePath = process.platform === "linux" ? "/dev/stdin" : "./예제.txt";
let input = fs.readFileSync(filePath).toString().trim();

// const fs = require('fs'); 
// let input = fs.readFileSync("/dev/stdin").toString().trim();


let cut = input.split('.');

const solution = () => {
    for (let i = 0; i < cut.length; i++) {
        if ((cut[i].length % 4) % 2 !== 0) {
            return -1;
        }
        else {
            const first = Math.floor(cut[i].length / 4);
            const second = Math.floor((cut[i].length % 4) / 2);
            cut[i] = "AAAA".repeat(first) + "BB".repeat(second);
        }
    }
    return cut.join('.')
}
console.log(solution());


🧵 참고한 정답지 🧵

https://kimbangg.tistory.com/208
https://junghyeonsu.tistory.com/260

💡💡 기억해야 할 점 💡💡

split('.')의 결과로 " " 도 나올 수가 있다.

profile
이건 대체 어떻게 만든 거지?

0개의 댓글