Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 | 31 |
Tags
- 개발자
- 프로그래머스
- 코테
- 코스닥
- 개발
- Reflex
- C++
- 자바정리
- 주가예측
- 사물인터넷
- 풀스택프레임워크
- 빅데이터
- 코딩
- 백준
- 이웃한 칸
- 프로그램
- 자바독학
- 코딩테스트
- java정리
- 코딩독학
- Python
- SNS
- backend
- Project
- 자바
- java
- frontend
- 개인프로젝트
- 프로그래밍
- 모의 주식
Archives
- Today
- Total
Creative Code
붕대 감기 본문
https://school.programmers.co.kr/learn/courses/30/lessons/250137
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
int solution(vector<int> bandage, int health, vector<vector<int>> attacks) {
int answer = 0;
int success = 0; // 연속 성공시간
int status_health = health; // 현재체력
int timeend = attacks[attacks.size() - 1][0]; //몬스터의 마지막 공격시간
int index = 0; // attacks 탐색 index
for (int i = 1; i <= timeend; i++) {
if (i == attacks[index][0]) { // 몬스터가 공격할 때
status_health -= attacks[index][1];
if (status_health <= 0) { // 캐릭터가 사망 시 -1을 리턴
return -1;
}
index++; // 캐릭터가 안죽었을 때 다음 index로 변경
success = 0; // 캐릭터가 공격받을 시 연속 회복시간 초기화
}
else { // 몬스터가 공격받지 않아 회복할 때
success += 1; // 연속 회복성공 시간 1초 추가
status_health += bandage[1]; // 체력 회복
if (success == bandage[0]) { // 연속 회복 모두 성공시 추가회복
status_health += bandage[2];
success = 0;
}
if (status_health >= health) { // 회복후 체력이 최대체력보다 많을시 최대체력으로 변경
status_health = health;
}
}
}
return status_health;
}
'프로그래머스 코테 문제 > LEVEL 1' 카테고리의 다른 글
가장 많이 받은 선물 (0) | 2024.04.12 |
---|---|
데이터 분석 (0) | 2024.04.12 |
이웃한 칸 (0) | 2024.04.12 |