문제 링크입니다: https://programmers.co.kr/learn/courses/30/lessons/42889
코딩테스트 연습 - 실패율
실패율 슈퍼 게임 개발자 오렐리는 큰 고민에 빠졌다. 그녀가 만든 프랜즈 오천성이 대성공을 거뒀지만, 요즘 신규 사용자의 수가 급감한 것이다. 원인은 신규 사용자와 기존 사용자 사이에 스
programmers.co.kr
간단한 구현 문제였습니다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <vector> | |
#include <algorithm> | |
using namespace std; | |
const int MAX = 500 + 1; | |
pair<int, int> statistics[MAX]; | |
bool cmp(pair<double, int> a, pair<double, int> b) | |
{ | |
if (a.first > b.first) | |
{ | |
return true; | |
} | |
if (a.first == b.first) | |
{ | |
if (a.second < b.second) | |
{ | |
return true; | |
} | |
} | |
return false; | |
} | |
vector<int> solution(int N, vector<int> stages) { | |
for (int stage : stages) | |
{ | |
for (int i = 1; i <= stage; i++) | |
{ | |
statistics[i].second++; | |
} | |
statistics[stage].first++; | |
} | |
vector<pair<double, int>> failureRates; | |
for (int i = 1; i <= N; i++) | |
{ | |
if (statistics[i].first == 0) | |
{ | |
failureRates.push_back({ 0, i }); | |
} | |
else | |
{ | |
failureRates.push_back({ double(statistics[i].first) / double(statistics[i].second), i }); | |
} | |
} | |
sort(failureRates.begin(), failureRates.end(), cmp); | |
vector<int> answer; | |
for (pair<double, int> ratio : failureRates) | |
{ | |
answer.push_back(ratio.second); | |
} | |
return answer; | |
} |

개발환경:Visual Studio 2017
지적, 조언, 질문 환영입니다! 댓글 남겨주세요~
반응형
'알고리즘 > programmers' 카테고리의 다른 글
[Programmers] [1차] 다트 게임 (0) | 2021.11.28 |
---|---|
[Programmers] 2016년 (0) | 2021.11.23 |
[Programmers] 크레인 인형뽑기 게임 (0) | 2021.11.20 |
[Programmers] 키패드 누르기 (0) | 2021.11.19 |
[Programmers] 숫자 문자열과 영단어 (0) | 2021.11.14 |