알고리즘 문제/C++

[프로그래머스] Level1 : 실패율 - C++

lingk 2020. 7. 3. 21:01
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

vector<int> solution(int N, vector<int> stages) {
	vector<int> answer;
	vector<double> ret;
	for (int i = 1; i <= N; i++) {
		answer.push_back(i);
	}
	for (int i = 1; i <= N; i++) {
		double bunmo = 0;
		double bunja = 0;
		for (int j = 0; j<stages.size(); j++) {
			if (i <= stages[j])
				bunmo++;
			if (i == stages[j])
				bunja++;
		}
		ret.push_back(bunja / bunmo);
	}
	    for(int i=0; i<N; i++) {
        for(int j=0; j<N-1; j++) {
            if (ret[j] < ret[j+1]) {
                swap(ret[j], ret[j+1]);
                swap(answer[j], answer[j+1]);
            }
        }
    }
	return answer;
}

 

반응형