프로그래머스 250137 (PCCP 기출문제) 1번 / 붕대 감기

1 개요[ | ]

프로그래머스 250137 (PCCP 기출문제) 1번 / 붕대 감기

2 C++[ | ]

#include <string>
#include <vector>
#include <iostream>
using namespace std;

int solution(vector<int> bandage, int health, vector<vector<int>> attacks) {
    int endSecond = attacks[attacks.size()-1][0];
    int attackIdx = 0;
    int success = 0;
    int hp = health;
    for(int i=1; i<=endSecond; i++) {
        if(i == attacks[attackIdx][0]) {
            hp -= attacks[attackIdx][1];
            if(hp <= 0 ) return -1;
            success = 0;
            attackIdx++;
            continue;
        }
        hp += bandage[1];
        success++;
        if(success == bandage[0]) {
            hp += bandage[2];
            success = 0;
        }
        if(hp > health) hp = health;
    }
    return hp;
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}