알고리즘/Programmers

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

chaeD2 2022. 5. 19. 14:29

(5/19 - O)

https://school.programmers.co.kr/learn/courses/30/lessons/42586

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

 

구현

Queue를 이용하여 풀이.

queue는 이터레이터가 없으므로 순회 X, 정 탐색하고 싶다면 Deque를 사용할 것.

 

 

Queue

https://chae-d-2.tistory.com/153?category=1098972 

 

std::queue

ref https://m.blog.naver.com/PostView.naver?isHttpsRedirect=true&blogId=cksdn788&logNo=220485144752 [Grind Away] c++ STL Queue에서는 탐색(검색)이 불가능합니다. 큐(queue)는 선입선출(FIFO)을 특징으로..

chae-d-2.tistory.com

 

코드

// 각 배포마다 몇 개의 기능이 배포되는가
// 배포는 하루에 한 번만, 하루의 끝에 이루어짐
// 예를 들어 진도율 95%이고 속도가 하루에 4인 작업은 배포가 2일 뒤에 이루어짐

#include <string>
#include <vector>
#include <queue>

using namespace std;

vector<int> solution(vector<int> progresses, vector<int> speeds) {
    vector<int> answer;
    int sz = progresses.size();
    queue<pair<int, int>> q;
    for (int i = 0; i < sz; i++) {
        q.push({ progresses[i], speeds[i] });
    }

    int day_cnt = 0;
    int out = 0;
    while (!q.empty()) {
		day_cnt++;
		int jindo = q.front().first + (q.front().second * day_cnt);
		if (jindo >= 100) {
			q.pop();
            out++;
			while (!q.empty()) {
				jindo = q.front().first + (q.front().second * day_cnt);
				if (jindo >= 100) {
					q.pop();
					out++;
				}
				else {
					break;
				}
			}
            answer.push_back(out);
            out = 0;
		}

	}


    return answer;
}

int main()
{
    vector<int> p = { 95, 90, 99, 99, 80, 99 };
    vector<int> s = { 1, 1, 1, 1, 1, 1};
    solution(p, s);
}