-
프로그래머스 - H-Index알고리즘 풀이/프로그래머스 2019. 12. 8. 02:47
문제 : https://programmers.co.kr/learn/courses/30/lessons/42747
코딩테스트 연습 - H-Index | 프로그래머스
H-Index는 과학자의 생산성과 영향력을 나타내는 지표입니다. 어느 과학자의 H-Index를 나타내는 값인 h를 구하려고 합니다. 위키백과1에 따르면, H-Index는 다음과 같이 구합니다. 어떤 과학자가 발표한 논문 n편 중, h번 이상 인용된 논문이 h편 이상이고 나머지 논문이 h번 이하 인용되었다면 h가 이 과학자의 H-Index입니다. 어떤 과학자가 발표한 논문의 인용 횟수를 담은 배열 citations가 매개변수로 주어질 때, 이 과학자의 H-
programmers.co.kr
풀이 :
h 은 1부터 돌면서 cnt를 센다. 조건에 맞게 cnt가 나온다면 즉 cnt 가 h 보다 크면서
남은 숫자 n-h 이하라면 답이 된다. 그러한 답 중 최댓값을 반환해주자.
코드 ( C++ )
This file contains 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; int solution(vector<int> citations) { int answer = 0; sort(citations.begin(), citations.end()); int n = citations.size(); for (int h = 1; h <= 1000; ++h) { int cnt = 0; for (int j = 0; j < n; ++j) { if (h <= citations[j]) cnt++; } if (cnt >= h && n - cnt <= h) { answer = max(answer, h); } } return answer; } '알고리즘 풀이 > 프로그래머스' 카테고리의 다른 글
프로그래머스 - 베스트앨범 (0) 2020.01.01 프로그래머스 - 다리를 지나는 트럭 (0) 2019.12.14 프로그래머스 - 숫자 야구 (0) 2019.12.06 프로그래머스 - 위장 (0) 2019.12.05 프로그래머스 - 탑 (0) 2019.12.03