(1).백준 32587번 Dragged-out Duel는 가위바위보에서 이겼는지를 묻는 문제로

주어진 조건들을 다 비교해가며 승리할 경우에 카운트를 더해주는 방식으로 진행한 다음

최종적으로 누가 더 많이 이겼는지를 삼항연산자로 비교해줬다.

const input = `6
PRSRPS
PSSPPR`.split('\n')

let a = 0
let b = 0

for(let i = 0 ; i < input[1].length ; i++){
    if(input[1][i] != input[2][i]){
        if(input[1][i] == 'R' && input[2][i] == 'S'){
            a++
        }
        else if(input[1][i] == 'R' && input[2][i] == 'P'){
            b++
        }
        else if(input[1][i] == 'S' && input[2][i] == 'P'){
            a++
        }
        else if(input[1][i] == 'S' && input[2][i] == 'R'){
            b++
        }
        else if(input[1][i] == 'P' && input[2][i] == 'R'){
            a++
        }
        else{
            b++
        }
    }
}

console.log(a > b ? 'victory' : 'defeat')

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

[개발일지] - 774(주말)  (1) 2025.08.16
[개발일지] - 773(광복절)  (0) 2025.08.15
[개발일지] - 770  (1) 2025.08.12
[개발일지] - 769  (0) 2025.08.11
[개발일지] - 768(주말)  (0) 2025.08.10

+ Recent posts