PCCP 기출문제 1번
문제/제한사항
입력/출력
문제 바로가기
PCCP 기출문제 1번
💡풀이방법
- 입출력 예를 보면, 시간이랑
attacks
의 배열 값의 첫번째 인덱스 값(공격시간)이 같은 경우 공격을 받게 된다.
- 변수
- current : 현재 체력
- count : 연속체력회복
- attack_fount : 공격여부
- 공격시간인 경우 (
attacks
배열값의 첫번째 값)
연속회복횟수 = 0
현재 체력 - 공격값
- 이때
현재 체력 < 0
or == 0
인 경우: return -1
- 공격시간 아닌 경우
bandage[1]
만큼 체력 회복
연속회복횟수 += 1
- 이때
연속회복횟수 == bandage[0]
인 경우: 현재 체력 + bandage[2]
👀전체코드
def control_health(num, max_):
print("control")
if num > max_:
print("health", max_)
return max_
else:
print("current", num)
return num
def solution(bandage, health, attacks):
current = health
count = 0
for i in range(1, attacks[-1][0] + 1):
current_attack = 0
attack_found = False
for subattack in attacks:
if i == subattack[0]:
current_attack = subattack[1]
attack_found = True
break
if attack_found:
current -= current_attack
count = 0
if current < 0 or current == 0:
return -1
else:
count += 1
if count == bandage[0]:
current = current + bandage[1] + bandage[2]
count = 0
else:
current += bandage[1]
current = control_health(current, health)
return current