본문 바로가기

Algorithm/프로그래머스

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

반응형

프로그래머스 : 기능개발

 

프로그래머스

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

programmers.co.kr

 


- 문제

  프로그레스와 속도가 주어질 때 가장 앞에 있는 프로그래스가 완료될 때 같이 완료되는 프로그래스의 수를 출력하는 문제다.

 


- 풀이

#include <string>
#include <vector>

using namespace std;

vector<int> solution(vector<int> progresses, vector<int> speeds) {
    vector<int> answer;
    int max;
    int once = 0;
    vector<int> times(progresses.size(),0);
    for(int i = 0; i < progresses.size(); i++){
        times[i] = (100-progresses[i] - 1)/speeds[i]+1;
    }
    times.push_back(101);
    max = times[0];
    for(int i = 0; i < times.size(); i++){
        if( max < times[i] || i == times.size()-1){
            max = times[i];
            answer.push_back(once);
            once = 1;
        }
        else{
            once++;
        }
        
    }
    return answer;
}

 

딱히 설명할 게 없는 문제다.

 

  


- 기억할 것!

 X

반응형