알고리즘/프로그래머스
[2019 KAKAO BLIND RECRUITMENT] 실패율
동 코
2020. 5. 7. 23:09
문제풀이
정렬하는 문제이다. 실패율이 같은 경우 번호 순서라서 이미 정렬된 상태라서 stable_sort를 이용하여 따로 번호정렬을 하지않았다.
소스코드
더보기
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef struct Stage{
int num;
int arrival;
int not_clear;
Stage(){}
Stage(int n){
num = n;
arrival = 0;
not_clear = 0;
}
}Stage;
vector<Stage> stage_infos;
bool cmp(Stage a, Stage b){
double failure_rateA = (double)a.not_clear/(double)a.arrival;
double failure_rateB = (double)b.not_clear/(double)b.arrival;
return failure_rateA>failure_rateB;
}
vector<int> solution(int N, vector<int> stages) {
vector<int> answer;
for(int i=1;i<=N;i++){
stage_infos.push_back(Stage(i));
}
for(int i=0;i<stages.size();i++){
for(int j=0;j<stages[i];j++){
stage_infos[j].arrival++;
}
stage_infos[stages[i]-1].not_clear++;
}
stable_sort(stage_infos.begin(), stage_infos.end(), cmp);
for(int i=0;i<stage_infos.size();i++){
answer.push_back(stage_infos[i].num);
}
return answer;
}
|
cs |
문제 링크 : www.programmers.co.kr/learn/courses/30/lessons/42889
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr