https://www.welcomekakao.com/learn/courses/30/lessons/42889

 

코딩테스트 연습 - 실패율

실패율 슈퍼 게임 개발자 오렐리는 큰 고민에 빠졌다. 그녀가 만든 프랜즈 오천성이 대성공을 거뒀지만, 요즘 신규 사용자의 수가 급감한 것이다. 원인은 신규 사용자와 기존 사용자 사이에 스��

www.welcomekakao.com

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int schk[200001];
vector <pair<double,int>> nlist;
bool cmp(pair<double,int> a,pair<double,int> b)
{
if(a.first != b.first) return a.first > b.first;
else return a.second < b.second;
}

vector<int> solution(int N, vector<int> stages) {
    vector<int> answer;
    
    for(int i=0;i<stages.size();i++){
        int chk = stages[i];
        schk[chk]++;
    }
    int cnt=stages.size();
    for(int i=1;i<=N;i++){
        if(cnt!=0){
            double k = 1.0*schk[i]/cnt;
            nlist.push_back({k,i});
            cnt-=schk[i];
            cout<<k<<" ";
        }else{
            nlist.push_back({0,i});
        }
    }
    sort(nlist.begin(),nlist.end(),cmp);
    for(int i=0;i<nlist.size();i++){
        answer.push_back(nlist[i].second);
    }
    return answer;
}

+ Recent posts