본문 바로가기

problem solving

[프로그래머스]기능개발

이전값이 완료되었을 때 현재값이 check배열이 true이면 카운트를 증가시켜주고 check를 true해준다.

한번 순회한 후에 현재 순차적으로 진행될 수 있도록 예외처리 해준 후 카운트가 0이 아닐 때 값을 푸쉬해준다.

#include <string>
#include <vector>
 
using namespace std;
 
bool check[110= { 0 };
 
vector<int> solution(vector<int> progresses, vector<int> speeds) {
    vector<int> answer;
    
    int cur = 0, count = 0;
    while (cur < progresses.size()) {
        for(int i = 0; i < progresses.size(); i++) {
            if(check[i]) { continue; }
            progresses[i] += speeds[i];
            if(progresses[i] >= 100 && (i == 0 || ( i > 0 && check[i - 1]))) { 
                check[i] = true;
                count++;
            }
        }
         
        if(!check[cur]) { continue; }
        cur++;
        if(!count) { continue; }
        answer.push_back(count);
        count = 0;
    }
    return answer;
}
cs

'problem solving' 카테고리의 다른 글

[프로그래머스]주식가격  (0) 2020.03.07
[프로그래머스]쇠막대기  (0) 2020.03.07
[프로그래머스]스킬트리  (0) 2020.03.07
[프로그래머스]탑  (0) 2020.03.07
[프로그래머스][1차] 다트 게임  (0) 2020.03.06