-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhIndex.cpp
More file actions
63 lines (47 loc) · 1.27 KB
/
hIndex.cpp
File metadata and controls
63 lines (47 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//
// Created by Mayank Parasar on 2020-01-29.
//
/*
* Given a list of publications of the number of citations a scholar has, find their h-index.
* Example:
Input: [3, 5, 0, 1, 3]
Output: 3
* */
#include <iostream>
#include <vector>
#include <map>
using namespace std;
int find_hindex(vector<int> citation_list) {
map<int, vector<int>> h_index;
// have key as h-index and
int h_idx = 1;
// search of number of citations greater than
// or equal to citation index. if found find the next citation
while (h_index[h_idx].size() < h_idx) {
int ii;
for(ii=0; ii < citation_list.size(); ii++) {
if(citation_list[ii] >= h_idx) {
h_index[h_idx].push_back(citation_list[ii]);
}
if(h_index[h_idx].size() == h_idx)
break;
// break and reset ii to 0
}
if ((ii == citation_list.size()) &&
h_index[h_idx].size() < h_idx)
break;
h_idx++;
}
for(auto i : h_index) {
cout << i.first << ": ";
for(auto k : i.second)
cout << k <<",";
cout << endl;
}
return (--h_idx);
}
int main() {
vector<int> citation = {3, 5, 0, 1, 3};
cout << find_hindex(citation);
return 0;
}