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

[백준/파이썬] 1362번 펫

by 현장 2022. 5. 27.

-Code

i = 0

while 1:
    i += 1
    result = ""
    dead = False
    o, w = map(int, input().split())
    if o == w == 0:
        break
    while 1:
        play, n = input().split()
        n = int(n)
        if play == '#' and n == 0:
            break
        if play == 'F':
            w += n
        else:
            w -= n
        if w <= 0:
            dead = True
    if dead:
        result = f"{i} RIP"
    else:
        if o / 2 < w < o * 2:
            result = f"{i} :-)"
        else:
            result = f"{i} :-("
    print(result)

한번 몸무게가 0 이하로 내려간 후 올라갔을 경우를 생각을 못해서 틀렸었습니다.