dev_eun
[프로그래머스] 기능개발 c++, javascript 본문
programmers.co.kr/learn/courses/30/lessons/42586?language=cpp
c++
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
vector<int> solution(vector<int> progresses, vector<int> speeds) {
vector<int> answer;
int sz = progresses.size();
int release = ceil((double)(100-progresses[0])/(double)speeds[0]);
int cnt = 0;
for(int i=0;i<sz;i++){
int days = ceil((double)(100-progresses[i])/(double)speeds[i]);
if(release < days || progresses[i] == 100){
answer.push_back(cnt);
release = days;
cnt = 1;
}
else cnt++;
}
answer.push_back(cnt);
return answer;
}
javascript
function solution(progresses, speeds) {
var answer = [];
let cnt = 0;
let release = Math.ceil((100-progresses[0])/speeds[0]);
for(let i = 0;i<progresses.length;i++){
let this_release = Math.ceil((100-progresses[i])/speeds[i]);
if(this_release <= release){
cnt++;
} else {
answer.push(cnt);
release = this_release;
cnt = 1;
}
}
answer.push(cnt);
return answer;
}
728x90
'공부 > 알고리즘 문제' 카테고리의 다른 글
맨날 잊어버려서 적어 놓는 코테 Tips (0) | 2021.05.03 |
---|---|
[프로그래머스] 괄호 회전하기 c++, javascript (0) | 2021.05.02 |
[프로그래머스] 순위 (0) | 2020.12.11 |
[백준] BOJ 1937번 욕심쟁이 판다 (0) | 2020.12.11 |
[프로그래머스] 가장 먼 노드 (0) | 2020.12.11 |