Softeer - 위험한 효도 (Python)

조민수·2024년 2월 2일

Softeer

목록 보기
6/20

Lv1, ⭐


문제 풀이

단순 구현 문제
더 쉽게 풀 방법도 있을 것 같다.

from sys import stdin

def calculate_cycle(a, b, d):
    cnt = 0
    now = 'back'

    while d > 0:
        if now == 'back':
            for i in range(a):
                d -= 1
                cnt += 1
                if d == 0:
                    return cnt
            now = 'front'
        elif now == 'front':
            cnt += b
            now = 'back'

    return cnt

a, b, d = map(int, stdin.readline().split())

# 첫 번째 순환
cnt = calculate_cycle(a, b, d)

# 매개변수 변경 후 두 번째 순환
a, b = b, a
cnt += calculate_cycle(a, b, d)

print(cnt)
profile
Being a Modern Project Manager

0개의 댓글