(1).백준 4564번 숫자 카드놀이는 숫자를 자릿수별로 분해해서 다시 곱한 다음 한자릿수가 될 때까지 반복하는 문제로

각 문자열을 string 형태로 잘라서 곱해준 다음 결과값이 한자릿수가 아니면 계속 반복하게 while문으로 처리했다.

 

while 조건은 1자리가 초과할 경우에만 작동하기 때문에

최종적으로는 문자열을 한번 더 담아서 합쳐서 출력해야 정상 처리됐다.

const input = `95
396
28
4
40
0`.split('\n')

for(let i = 0 ; i < input.length - 1 ; i++){
    const result = []
    let str = input[i]
    while (str.length > 1) {
        result.push(str)
        const strList = str.split('')
        let newStr = 1
        for(let j = 0 ; j < strList.length ; j++){
            newStr *= strList[j]
        }
        str = String(newStr)
    }
    result.push(str)
    console.log(result.join(' '))
}

'회고' 카테고리의 다른 글

[개발일지] - 883  (0) 2025.12.11
[개발일지] - 882  (0) 2025.12.10
[개발일지] - 880(주말)  (0) 2025.12.08
[개발일지] - 879(주말)  (0) 2025.12.07
[개발일지] - 878  (0) 2025.12.06

+ Recent posts