본문 바로가기
알고리즘/프로그래머스

[ 프로그래머스 / sort ] H-Index

by 뎁꼼 2020. 6. 29.

1. 문제


 

 

코딩테스트 연습 - H-Index

H-Index는 과학자의 생산성과 영향력을 나타내는 지표입니다. 어느 과학자의 H-Index를 나타내는 값인 h를 구하려고 합니다. 위키백과1에 따르면, H-Index는 다음과 같이 구합니다. 어떤 과학자가 발표

programmers.co.kr

 

2. 소스코드


- 정렬 후, 정답이 될 수 있는 값보다 크거나 같은 지 비교해주면된다.

 

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

using namespace std;

int solution(vector<int> citations) {
    
    int size = citations.size();
    int answer = size;
    sort(citations.begin(), citations.end());
    for(int i = 0 ; i < size; ++i){
        if(citations[i] >= answer) return answer;
        else answer--;
    }
}