카카오 코딩 테스트 풀이
실패율 풀이
by paysmile
2019. 9. 1.
#include <string>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
using namespace std;
const int MAX = 501;
bool cmp(pair<double, int> a, pair<double, int> b) {
if (a.first > b.first)
return true;
else if (a.first == b.first) {
if (a.second < b.second)
return true;
else
return false;
}
return false;
}
vector<int> solution(int N, vector<int> stages) {
vector<int> answer;
int num[MAX],current[MAX];
vector<pair<double, int>> value;
memset(num, 0, sizeof(num));
memset(current, 0, sizeof(current));
for (int i = 0; i < stages.size(); i++) {
int index = stages[i];
for (int j = index; j >= 1; j--) {
num[j] ++;
}
current[index] ++;
}
for (int i = 1; i <= N; i++) {
if (num[i] == 0)
value.push_back(make_pair(0, i));
else
value.push_back(make_pair(current[i] / (double)num[i], i));
}
sort(value.begin(), value.end(), cmp);
for (int i = 0; i < N; i++)
answer.push_back(value[i].second);
return answer;
}