Algorithm/C++ - 프로그래머스
프로그래머스 Level2 - H-Index C++
ㅇㅇ잉
2021. 3. 26. 01:11
문제 자체가 이게 뭔말이지? 싶었지만 아래 링크된거 보고 어떻게 풀지 감이 잡혔다.
https://en.wikipedia.org/wiki/H-index
h-index - Wikipedia
From Wikipedia, the free encyclopedia Jump to navigation Jump to search Author-level metric that attempts to measure the productivity and citation impact of the publications of a person The h-index is an author-level metric that measures both the productiv
en.wikipedia.org
예시
[3, 0, 6, 1, 5] 를 내림차순으로 정렬한다.
=> [6, 5, 3, 1, 0]
: 총 5편 논문 중에서 3편의 논문이 3회 이상 인용됨
1. 내림차순으로 정렬
2. citations[index]가 index보다 크면 answer++해준다.
for문의 i를 index로 사용한다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int solution(vector<int> citations) {
int answer = 0;
sort(citations.rbegin(),citations.rend());
for(int i=0;i<citations.size();++i){
if(citations[i]>=i+1) ++answer;
}
return answer;
}
|
cs |