YeJin's Footsteps

H-Index 본문

Computer Science & Engineering/알고리즘

H-Index

YeJinii 2021. 7. 1. 18:10

이 문제를 해결하는 가장 빠른 방법은 문제에 첨부된 위키백과를 참고하는 것이다.

"answer"는 citations 내에 없을 수도 있다.

 

문제 링크

https://programmers.co.kr/learn/courses/30/lessons/42747

 

코딩테스트 연습 - H-Index

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

programmers.co.kr

 

풀이 코드

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

using namespace std;

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

'Computer Science & Engineering > 알고리즘' 카테고리의 다른 글

프린터  (0) 2021.07.02
기능 개발  (0) 2021.07.02
가장 큰 수  (0) 2021.07.01
불량사용자  (0) 2021.05.07
신규 아이디 추천  (0) 2021.05.02
Comments