[프로그래머스] Level.2 정렬-H-Index
2021. 1. 15. 17:21ㆍAlgorithm/프로그래머스
코딩테스트 연습 - H-Index
H-Index는 과학자의 생산성과 영향력을 나타내는 지표입니다. 어느 과학자의 H-Index를 나타내는 값인 h를 구하려고 합니다. 위키백과1에 따르면, H-Index는 다음과 같이 구합니다. 어떤 과학자가 발표
programmers.co.kr
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int solution(vector<int> citations) {
int answer = 0;
int use,no,h_idx = 0;
sort(citations.rbegin(), citations.rend());
int h=citations[0];
while(1){
use=0,no=0;
for (int i = 0;i < citations.size();i++) {
if (h <= citations[i]) use++;
if (citations[i] <= h) no++;
}
if ((h<=use&&no<=h)||h==0) {
h_idx = h;
break;
}
else h--;
}
answer = h_idx;
return answer;
}
'Algorithm > 프로그래머스' 카테고리의 다른 글
[프로그래머스] Level.2 연습문제-피보나치 수 (0) | 2021.01.16 |
---|---|
[프로그래머스]Level.2 완전탐색-카펫 (0) | 2021.01.16 |
[프로그래머스] Level.2 해시- 위장 (0) | 2021.01.15 |
[프로그래머스] Level.2 해시- 전화번호 목록 (0) | 2021.01.15 |
[프로그래머스]Level.2 탐욕법(greedy) 구명보트 (0) | 2021.01.14 |