관리 메뉴

fatalite

C++ 기능개발 [고득점 Kit : 스택 / 큐] 본문

카테고리 없음

C++ 기능개발 [고득점 Kit : 스택 / 큐]

fataliteforu 2023. 5. 13. 09:31

Problem

난이도 : 프로그래머스 2단계

분류 : 큐(deque)

 

Solution

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

vector<int> solution(vector<int> progresses, vector<int> speeds) {
    vector<int> answer;
    //length of processes
    int length = progresses.size();
    deque<pair<int, int>> q;
    for(int i=0 ; i < length;i++){
        q.push_back({progresses[i], speeds[i]});
    }
    
    while(!q.empty()){
        int i = 0;
        for(int j =0; j < q.size(); j++){
            q[j].first += q[j].second;
        }
        while(q.front().first >= 100){
                i++;
                q.pop_front();
        }
        if(i != 0) answer.push_back(i);
    }
    
    return answer;
}