https://programmers.co.kr/learn/courses/30/lessons/42586?language=cpp
코딩테스트 연습 - 기능개발
프로그래머스 팀에서는 기능 개선 작업을 수행 중입니다. 각 기능은 진도가 100%일 때 서비스에 반영할 수 있습니다. 또, 각 기능의 개발속도는 모두 다르기 때문에 뒤에 있는 기능이 앞에 있는
programmers.co.kr
내 손으로 풀어서 뿌듯했던 문제.
논리는 이렇다.
pair<int, int>쌍에 각각 progress, speed 정보를 하나씩 저장해놓고,
한 타임 돌 때마다 pair.first 에 pair.second를 더해준 뒤,
while(pair.first >= 100){
pair를 담고 있는 컨테이너의 가장 앞을 pop.
}
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> V;
vector<int> solution(vector<int> progresses, vector<int> speeds) {
vector<int> answer;
for (int i = 0; i < progresses.size(); i++)
{
pair<int, int> t;
t.first = progresses[i];
t.second = speeds[i];
V.push_back(t);
}
while (!V.empty())
{
int t = 0;
for (int i = 0; i < V.size(); i++)
{
V[i].first += V[i].second;
}
while (!V.empty() && V[0].first >= 100)
{
t++;
V.erase(V.begin());
}
if (t != 0)
answer.push_back(t);
}
return answer;
}
'Algorithm' 카테고리의 다른 글
프로그래머스[c++] 로또의 최고 순위와 최저 순위 (0) | 2021.05.25 |
---|---|
프로그래머스 - 카펫 c++ (0) | 2021.05.23 |
프로그래머스 소수 만들기 c++ (0) | 2021.05.23 |
boj 1992 (0) | 2021.02.26 |
boj 1780 (0) | 2021.02.25 |
최근댓글