본문 바로가기
Beakjoon&프로그래머스/파이썬

[백준/파이썬] 9358번 순열 접기 게임

by 현장 2024. 6. 7.

-Code

from collections import deque

for t in range(1, int(input()) + 1):
    n = int(input())
    nums = deque(list(map(int, input().split())))

    while len(nums) != 2:
        temp = deque()
        while nums:
            front = nums.popleft()
            if nums:
                back = nums.pop()
                temp.append(front + back)
            else:
                temp.append(front * 2)
        nums = temp

    res = "Alice" if nums[0] > nums[1] else "Bob"
    print(f"Case #{t}: {res}")

큐로 꺼내는 과정에서 한번에 front와 back을 한번에 뽑아 계산하는 방법을 사용해서 여러번 틀렸었습니다.