본문 바로가기
프로그래머스/lv.1

[PCCP 기출문제] 1번 / 붕대 감기

by bingual 2024. 1. 31.
반응형

 

https://school.programmers.co.kr/learn/courses/30/lessons/250137

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

문제풀이

입출력 예시를 보면서 언제 회복을 하는지 체킹하는게 핵심이다.

def solution(bandage, health, attacks):
    n = max(attacks)[0]

    t, x, y = bandage
    current_health, healing, casting = health, 0, 0

    for i in range(1, n + 1):
        healing += 1
        casting += 1

        # 공격 받을시 체력 차감 및 스킬 재시전
        for attack in attacks:
            if attack[0] == i:
                current_health -= attack[1]
                healing, casting = 0, 0

        # 캐릭터가 죽으면 -1 반환
        if current_health <= 0:
            return -1

        # 공격 받지 않았을 때만 체력 회복
        if healing != 0 and casting != 0:
            current_health += x

        # 추가 회복량만큼 체력 회복
        if casting == t:
            current_health += y

        # 시전 시간이 끝나면 재시전
        if healing == t:
            healing, casting = 0, 0

        # 최대 체력만큼 회복 불가
        if current_health > health:
            current_health = health

    answer = current_health
    return answer

'프로그래머스 > lv.1' 카테고리의 다른 글

가장 많이 받은 선물  (0) 2024.02.01
신고 결과 받기  (1) 2024.01.31
개인정보 수집 유효기간  (0) 2024.01.30
[PCCE 기출문제] 10번 / 데이터 분석  (0) 2024.01.30
성격 유형 검사하기  (0) 2024.01.30