(1).백준 24830번 Broken Calculator는 계산기가 특이한 규칙으로 변경되었을 때

입력된 값을 처리하면 어떻게 출력되는지를 구해야 하는 문제였다.

 

각 기호에 맞는 조건에 따라 이전 값 처리 또는 현재 값 등록 등의 처리를 진행했고

최대 10의 18승인 100경까지 갈 수 있다는 조건이 있기 때문에 BigInt 처리했다.

const input = `5
4 * 5
2 + 5
3 - 1
20 / 3
13 / 24`.split('\n')

let before = 1n
const result = []

for(let i = 1 ; i < input.length ; i++){
    const [a, x, b] = input[i].split(' ')
    if(x == '*'){
        let resultB = BigInt(a) * BigInt(b) * BigInt(a) * BigInt(b)
        before = resultB
        result.push(resultB)
    }
    else if(x == '/'){
        let resultB = (BigInt(a) + 1n)/ 2n
        before = resultB
        result.push(resultB)
    }
    else if(x == '+'){
        let resultB = BigInt(a) + BigInt(b) -  before
        before = resultB
        result.push(resultB)
    }
    else if(x == '-'){
        let resultB = (BigInt(a) - BigInt(b)) * before
        before = resultB
        result.push(resultB)
    }
}

console.log(result.join('\n'))

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

[개발일지] - 321  (0) 2024.05.17
[개발일지] - 320  (0) 2024.05.16
[개발일지] - 319  (0) 2024.05.14
[개발일지] - 318  (0) 2024.05.13
[개발일지] - 317(주말)  (0) 2024.05.12

+ Recent posts