이 페이지는 코딩도장 데이터의 읽기 전용 정적 보관본입니다.

h-index & g-index

연구자의 연구업적을 평가할 때 사용되는 지표 중 h-index와 g-index라는 것이 있다.

  • h-index : 인용 횟수가 h번 이상인 논문이 h개일 때 가능한 h의 최댓값
  • g-index : 인용 횟수가 높은 상위 g개 논문의 인용 횟수 총합이 g²이상일 때 가능한 g의 최댓값

어떤 학자가 쓴 논문 각각의 인용 횟수가 주어질 때, h-index와 g-index를 계산하시오.

e.g.)

  • 입력 : 0 15 4 0 7 10 0
  • h-index : 4
  • g-index : 6

2015/11/02 20:50

김 정우

h번 이상인 논문이 h개 "이상"일 때 라고 해야 정확할 것 같습니다. 만약 예시 입력에서 5가 하나 더 있어 0 15 4 0 7 10 0 5 라면, 인용5회 이상이 4개, 인용4회 이상이 5개, ... 니까 가능한 h가 없습니다. - Noname, 2017/07/05 23:54

69개의 풀이가 있습니다.

def findH(index):
    index.sort(reverse=True)
    for i, j in enumerate(index):
        if (i+1) == j : return index[i]
    return None

def findG(index):
    index.sort(reverse=True)
    sum = 0
    for i, j in enumerate(index):
        sum =  sum + j
        if (i+1)**2 > sum : return i
    return None

index = [0,15,4,0,7,10,0]

print('h-Index : ' + str(findH(index)))
print('g-Index : ' + str(findG(index)))

2015/11/14 06:01

이 규환

# 한글 처리 in Atom 1.21.1 + Anaconda(Python 3.6.3)
import sys
import io

sys.stdout = io.TextIOWrapper(sys.stdout.detach(), encoding='utf-8')
sys.stderr = io.TextIOWrapper(sys.stderr.detach(), encoding='utf-8')

# 연구자의 연구업적을 평가할 때 사용되는 지표 중 h-index와 g-index라는 것이 있다.
# h-index : 인용 횟수가 h번 이상인 논문이 h개일 때 가능한 h의 최댓값
# g-index : 인용 횟수가 높은 상위 g개 논문의 인용 횟수 총합이 g²이상일 때 가능한 g의 최댓값
# 어떤 학자가 쓴 논문 각각의 인용 횟수가 주어질 때, h-index와 g-index를 계산하시오.

quotations = [0, 15, 4, 0, 7, 10, 0]

# h-index
for h in range(min(max(quotations), len(quotations)), 0, -1):
    count = 0
    for number in quotations:
        if number >= h:
            count += 1
    if count == h:
        print("h-index =", h)
        break

# g-index
quotations.sort(reverse=True)
for g in range(len(quotations), 0, - 1):
    if sum(quotations[0:g]) >= g**2:
        print("g-index =", g)
        break

2017/10/31 08:03

Jace Alan

와..이건 문제도 답도 원리를 이해하기 힘드네요 ㅠㅠ - june davis, 2017/12/20 15:17

Python 3.5 입니다. g-index 문제 반대로 이해하고 한참을 헤맸네요.

# Function to find h-index
def FindHIndex(cntList):
    cntDict = {}

    for cnt in cntList:
        cntDict[cnt] = 1 + (0 if cntDict.get(cnt) is None else cntDict.get(cnt))

    beforeCnt = 0

    for cnt in sorted(cntDict, reverse = True):
        cntDict[cnt] += beforeCnt
        beforeCnt = cntDict[cnt]

        if cntDict[cnt] >= cnt:
            return cnt

# Function to find g-index
def FindGIndex(cntList):
    sumList = sorted(cntList, reverse = True)

    beforeSum = 0

    for i in range(len(sumList)):
        sumList[i] += beforeSum
        beforeSum = sumList[i]

        if i * i >= sumList[i]:
            return i

# Main
# Input string
input = '0 15 4 0 7 10 0'

# Input list from input string
quoteCnt = [int(x) for x in input.split(' ')]

# Find h-index
hIndex = FindHIndex(quoteCnt)
print('h-index: '+str(hIndex))

# Find g-index
gIndex = FindGIndex(quoteCnt)
print('g-index: '+str(gIndex))

2015/11/03 01:01

Donald

paperquote = [ 0, 15, 4, 0 , 7, 10, 0 ]

paperquote.sort(reverse=True)

for i in range( max( paperquote ) ) :
    cnt = 0
    for j in paperquote :
        if j >= i : cnt += 1
    if cnt < i : print "h-index : %d"%(i-1) ; break

for i in range(1, len( paperquote ) + 1 ) :
    cnt = 0
    sum = 0
    for j in paperquote :
        cnt += 1
        sum += j
        if cnt == i : break 
    if ( sum < i * i ) : print "g-index : {0}".format(i-1) ; break

2015/11/03 09:17

Kim JungRae

아 이 방식으로는 g-index가 전체 논문 인용횟수와 같을 때 출력이 안 되네요.... - Kim JungRae, 2015/11/03 09:18
#include <iostream>
#include <map>
#include <functional>
#include <cmath>

using namespace std;

int main(int argc, const char * argv[]) {

    int n;
    cin >> n; // 논문 데이터의 개수

    map<int, int, greater<int>> t_map;
    for (int i = 0; i < n; i++) { // 논문 인용횟수 입력 루프
        int r;
        cin >> r;

        if (t_map.find(r) != t_map.end()) {
            t_map[r]++;
        } else t_map[r] = 1;
    }

    // h-index, g-index 계산부
    int g = 0;
    bool g_found = false;
    int h = 0;
    bool h_found = false;
    int c = 0;
    int r = 0;
    for (auto i : t_map) {
        c += i.second;
        if (!h_found && c >= i.first) {
            h = c;
            h_found = true;
        }
        int r_i = i.first * i.second + r;
        if (!g_found) {
            int c_2 = c * c;
            if (r_i >= c_2) {
                g = c;
                r = r_i;
            } else {
                if (i.first > 0) {
                    g += floor((i.first - 2 * g + sqrt(i.first * (i.first - 4 * g) + 4 * r)) * 0.5); // 2차방정식 근의 공식에 따른 일반해
                } else {
                    g = floor(sqrt(r));
                }
                g_found = true;
            }

        }
        if (g_found && h_found) break;
    }

    cout << "h-index : " << h << endl;
    cout << "g-index : " << g << endl;

    return 0;
}

2015/11/04 17:23

Chromatics

c++로 작성하였습니다.

#include <iostream>
using namespace std;

int main()
{
    int h_index = 0, g_index = 0;
    int index[7] = { 0, 15, 4, 0, 7, 10, 0 };
    int temp = 0;
    for (int i = 0; i < sizeof(index) / sizeof(int); i++) {
        if (i + 1 <= index[i])
            h_index++;

        temp += index[i];
        if (temp >= (i + 1) * (i + 1))
            g_index++;

    }
    cout << "h_index : " << h_index << endl;
    cout << "g_index : " << g_index << endl;

    return 0;
}

2015/12/05 17:32

에카

Cite_Index = [0, 15, 4, 0, 7, 10, 0]
Cite_Index.sort(reverse=True)

h_index = 1

while True:
    for x in range(len(Cite_Index)):
        if Cite_Index[x] < h_index:
            break
    if x > h_index:
        h_index += 1
    elif x == h_index:
        break
    else:
        print('There is no h_index')
        h_index = 0
        break

for x in range(1,len(Cite_Index)+1):
    if sum(Cite_Index[:x]) < x ** 2:
        g_index = x-1
        break

print('h_index:  %d\ng_index:  %d' % (h_index,g_index))

인용횟수가 모두 0인 경우도 고려하였습니다.

2015/12/31 10:10

SPJung

L = [0,15,4,0,7,10,0]
def h_index(L):
    index = 0
    while True:
        if len(filter(lambda x : x>=index, L))>=index: index +=1
        else : return index-1
def g_index(L):
    index = 0
    while True:
        if sum(sorted(L,reverse=True)[0:index])>=index*index : index +=1
        else : return index-1

print h_index(L)
print g_index(L)

2016/01/13 22:14

상파

파이썬3.4입니다.

idx = [0, 15, 4, 0, 7, 10 ,0]

cnt = 0
h_index = []
for h in range(1, len(idx) + 1):
    for i in idx: 
            if i >= h: cnt += 1
    if h == cnt: h_index.append(h)
    cnt = 0
print('h-index: {}'.format(max(h_index)))

g_index = []
idx.sort(reverse = True)
for g in range(1, len(idx) + 1):
    if sum(idx[:g]) >= g ** 2: g_index.append(g)
print('g-index: {}'.format(max(g_index)))   

2016/03/20 00:49

디디

파이썬입니다.

def h(xs):
    return max([x for x in xs if len([y for y in xs if y >= x]) == x])

def g(xs):
    return max([g for g in range(1, len(xs)) 
               if sum(sorted(xs, reverse=True)[:g]) >= g**2])

d = [int(x) for x in input().split()]
print("h-index: {}".format(h(d)))
print("g-index: {}".format(g(d)))

2016/03/23 09:04

룰루랄라

constructor에서 입력값은 받고 있습니다.


    // 0 , 15, 4, 0, 7, 10, 0
    int indexOfQuote[];
    public HIndexGIndex(){

    }

    public HIndexGIndex(int[] index){
        this.indexOfQuote = index;
    }
    public int getGIndex(){
        int total = 0 , g = 0 ;

        // 1. check count of quote
        for(int i = 0 ;i < indexOfQuote.length ;i++){
            if(indexOfQuote[i] !=0) {
                total += indexOfQuote[i];
            }
        }

        g = (int) Math.sqrt((double)total);

        return g;

    }

    public int getHIndex(){
        int count= 0, h_index= 0;
        // 1. check count of quote
        for(int i = 0 ;i < indexOfQuote.length ;i++){
            if(indexOfQuote[i] !=0) {
                count++;
            }
        }
        // 2. check count of the over than h numbers.
        for(int j = 0 ; j < indexOfQuote.length ;j++){
            if( indexOfQuote[j] >= count){
                h_index++;
            }
        }

        return h_index;

    }

2016/04/12 22:48

xeo

def h_index(li):
    highest = list(sorted(li))[-1]
    result = []
    for h in range(highest):
        qtd = list((1 if i>=h else 0 for i in li)).count(1)
        if qtd == h:
            result.append(h)
    if len(result) != 0:
        return max(result)

def g_index(li):
    rvrsd = list(reversed(sorted(li)))
    result = []
    for g in range(len(rvrsd)):
        t = rvrsd[:g+1]
        if sum((x**2 for x in t)) > g**2:
            result.append(g)
    if len(result) != 0:
        return max(result)

while __name__ == '__main__':
    li = list(int(x) for x in input(">>>").split())
    print(h_index(li))
    print(g_index(li))

풀긴 풀었는데 문제가 이해가 안되네요;; 혹시 잘못된 것이 있으면 알려주세요.

2016/04/14 12:01

Flair Sizz

C#으로 작성했습니다.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Coding
{
    public static class Question095ProfessorIndexes
    {

        public static void Answer()
        {
            var inputs = new List<int> { 15, 10, 7, 4, 0, 0, 0 };
            ProfessorIndexes(inputs);
        }

        public static void ProfessorIndexes(List<int> inputs)
        {
            var hIndex = GetHIndex(inputs);
            var gIndex = GetGIndex(inputs);
        }

        public static int GetHIndex(List<int> inputs)
        {
            for (int i = inputs.Count; i > 0; i--)
                if (inputs.Count(c => c >= i) == i) return i;
            return 0
        }

        public static int GetGIndex(List<int> inputs)
        {
            var sum = inputs.Sum();
            for (int i = inputs.Count; i > 0; i--)
            {
                if (i * i == sum) return i;
                else sum -= inputs[i - 1];
            }
            return 0;
        }

    }
}

2016/05/31 23:01

Straß Böhm Jäger

Ruby

paper_eval_by_citations = ->str, cs=str.split.map(&:to_i) do
  puts "hidx : #{ cs.select {|h| cs.count {|e|e >= h} == h }.max }"
  puts "gidx : #{ (0..cs.size).select {|g| cs.max(g).sum >= g**2 }.max }"
end

Test

expect { paper_eval_by_citations["0 15 4 0 7 10 0"] }.
                to output( "hidx : 4\ngidx : 6\n" ).to_stdout

Output

#=> paper_eval_by_citations["0 15 4 0 7 10 0"]
hidx : 4
gidx : 6

2016/07/28 19:27

rk

def find_h_g_index(input):
    #convert input string to integer list
    score = [int(n) for n in input.split()]

    #find h index
    h_candidate = [x for x in score if x > 0]
    h_index = len(h_candidate)

    #find g index
    g_candidate = sorted(score)
    g_index = 0
    for i in range(1, len(g_candidate)):
        #slicing list starting from the end
        if i^2 <= sum(g_candidate[-i:]):
            g_index = max(g_index, i)


    return h_index, g_index

print(find_h_g_index(' 0 15 4 0 7 10 0'))

문제를 잘 못이해해서 조금 헤맸네요 ^^;;;

2016/09/18 10:51

Kim Sean

index = [0, 15, 4, 0, 7, 10, 0]
index.sort(reverse=True)
h_index = 0
g_index = 0
for i in range(len(index)):
    if i + 1 <= index[i]:
        h_index = i+1
    else:
        break 
for i in range(1, len(index) + 1):
    g2 = i**2
    if sum(index[0:i]) >= g2:
        g_index = i
    else:
        break
print('h-index : %d' % h_index)
print('g-index : %d' % g_index)

Python 3.5.2에서 작성하였습니다.

2016/11/24 10:59

Yeo HyungGoo

a = input("논문의 인용횟수를 적으세요 = ")
a_list = a.split(" ")
num =[]
for i in a_list:
    num.append(int(i))
num.sort()
num.reverse()

true_num = len(num) - num.count(False)     
while 1:
    big = []
    for i in range(0, len(num) - 1):
        if num[i] >= true_num:
            big.append(num[i])
    number = len(big)

    if number == true_num:
        print("h-index = " + str(true_num))
        break

    else:
        true_num = true_num -1


string = len(num)   #string = 14
while 1:
    sum=0
    for i in range(0, string-1):
        sum = sum + num[i]
    if sum >= string**2:
        print("g-index = " + str(string))
        break
    else :
        string = string -1

2016/12/08 00:48

Kim Da Seul

include

include

void sorting(int arr[], int n) { int i, j; for (i = 0; i < n; i++) { for (j = 0; j < (n-i-1); j++) { if (arr[j] < arr[j+1]) { int tmp = arr[j]; arr[j] = arr[j+1]; arr[j+1] = tmp; } } } return; }

int h_index(int arr[], int n) { int i, N = 0; while(1) { int cnt = 0; for (i = 0; i < n; i++) { if (N <= arr[i]) cnt++; } if (cnt < N) return (N-1); N++; } }

int g_index(int arr[], int n) { int i, N = 0; int arr2 = (int)malloc(sizeof(int)*n); for (i = 0; i < n; i++) { arr2[i] = arr[i]; } sorting(arr2, n);

while(1) {
    int sum = 0;
    for (i = 0; i < N; i++) { sum += arr2[i]; }
    if (sum < N*N) { free(arr2); return (N-1); }
    N++;
}

}

int main() { int i, n; printf("How many? : "); scanf("%d", &n); int arr = (int)malloc(sizeof(int)*n); for (i = 0; i < n; i++) { scanf("%d", arr+i); }

printf("h-index : %d\n", h_index(arr, n));
printf("g-index : %d\n", g_index(arr, n));
free(arr);
return 0;

}

2016/12/18 22:20

리코둔

h = max([len([1 for y in [0,15,4,0,7,10,0] if y > x]) for x in [0,15,4,0,7,10,0]])
print('h-index :', h)

_list = [0,15,4,0,7,10,0]
g,step, result = 0,0,0
for x in sorted(_list,reverse=True):
    step += 1
    result += x
    if step**2 >= result:
        g = step
        break
print('g-index :', g)

#### 2017.01.18 D-400 ####

문제를 잘이해한건가 모르게써여.

2017/01/18 23:51

GunBang

def paper(data):
    data.sort()
    data.reverse()
    n=len(data)
    h=n
    g=n
    while 1:
        if sum(1 for x in data if x>=h)>=h:
            break
        else:
            h-=1
    while 1:
        if sum(x for x in data[0:g])>=g**2:
            break
        else:
            g-=1
    print("h-index = %d, g-index = %d" %(h,g))
paper([0, 15, 4, 0, 7, 10, 0])


2017/02/14 01:32

김구경

sort, cumsum 등의 함수를 이용했습니다

% input
input_arr=[0 15 4 0 7 10 0];

% sorting
sorted_citation_num=sort(input_arr,'descend');
h_index=find((1:length(input_arr))     >=sorted_citation_num,1,'first')
g_index=find((1:length(input_arr)).^2 >=cumsum(sorted_citation_num),1,'first')


2017/03/02 01:32

c0din9

import java.util.Arrays;

public class HindexGindex {

    public static void main(String[] args) {
        Integer[] i = new Integer[]{0, 15, 4, 0, 7, 10, 0};
        long c = Arrays.asList(i).stream().filter(j -> j != 0).count();
        long h = Arrays.asList(i).stream().filter(k -> k >= c).count();
        double g = Math.sqrt(Arrays.asList(i).stream().mapToInt(Integer::intValue).sum());
        System.out.printf("h-index : %s , g-index : %s", h, g);
    }
}

문제 뜻을 몰라 한참을 ...

2017/03/14 10:59

genius.choi

quote = [0,15,4,0,7,10,0]

def h_index(quote):
    quote.sort(reverse=True)
        m = []
        n = []
    for h in range(len(quote)):
        for q in quote:
            if q >= h: m.append(h)
        if m.count(h) == h : n.append(h)
    return sorted(n)[0]


def g_index(quote):
    sum = 0
    count = 0
    g =[]
    quote.sort(reverse=True)
    for q in quote:
        sum += q
        count += 1
        if sum >= count**2:
            g.append(count)
    return max(g)

2017/03/17 16:25

ken choi

python 3.4.2

def find_index(sort,cal):
    for j in range(len(sort)):
        if sort[j] >= cal[j]:
            index = sort[j]
            break
    return index

cit = ['0','15','4','0','7','10','0']
cit_int = list(map(int, cit))
num_paper = len(cit)

h = [x for x in range(1,num_paper+1)]
g = [y**2 for y in range(1,num_paper+1)]
h_list = sorted(cit_int, reverse=True)
sum = 0
g_list = []
for i in range(num_paper):
    sum += cit_int[i]
    g_list.append(sum)

h_index = find_index(h,h_list)
g_index = find_index(g,g_list)

2017/04/27 06:52

예강효빠

a = input("입력 : ")
No = [int(x) for x in a.split(' ')]
com = []
for i in range(len(No)):
    Count = 0
    for j in range(len(No)):
        if No[j] >= i:
            Count += 1
    if Count == i:
        com.append(i)
print("h-index : %d" % max(com))
No.sort()
com1 = []
for i in range(len(No)):
    Count = 0
    for j in range(len(No)):
        if sum([x for x in No[-j:]]) >= i ** 2:
            com1.append(i)
print("g-index : %d" % max(com1))

2017/05/30 16:26

Jaehwi Han

list = [0,15,4,0,7,10,0]
list.sort(reverse = True)
len = len(list)

for cnt in range(1, len+1):
    h = list[cnt-1]
    if h <= cnt:
        print('h-index =', h)
        break

sum = 0
for g in range(1, len+1):
    sum += list[g-1]
    if sum < g**2:  # ** 연산자 그냥 한번 써 봤음
        print('g-index =', g-1)
        break

if g > len:
    print('g-index =', len)

푸는 거보다 문제를 이해하는 게 어렵네요.

2017/07/06 00:06

Noname

JAVA

    public static void main(String[] args) {
        int[] list = {0, 15, 4, 0, 7, 10, 0};
        int len = list.length;
        int highNum = 0;
        int cnt = 0;
        int result = 0;
        int square = 0;
        int sum = 0;

        Arrays.sort(list);
        highNum = list[len - 1];

        for(int i = 0; i <= highNum; i++) {
            for(int j = 0; j < len; j++) {
                if(list[j] >= i) {
                    cnt++;
                }
            }

            if(i == cnt) {
                result = i;
            }

            cnt = 0;
        }

        System.out.println("h-index: " + result);

        for(int i = 1; i <= len; i++) {
            square = i * i;
            for(int j = len - 1; j >= len - i; j--) {
                sum += list[j];
            }

            if(sum >= square) {
                result = i;
            }

            sum = 0;
        }

        System.out.println("g-index: " + result);
    }

2017/08/30 15:08

androot

# python 3.6
inp = "0 15 4 0 7 10 0"
inpg = list(sorted(map(int, inp.split()), reverse=True))
inph = list(filter(bool, inpg))
h_idx = 0
for h in range(1, len(inph) + 1):
    if len([cited for cited in inph if cited >= h]) >= h:
        h_idx = h
g_idx = 0
for g in range(1, len(inpg) + 1):
    if sum(inpg[:g]) >= g**2:
        g_idx = g
print("h-index: %d\ng-index: %d\n" % (h_idx, g_idx))

2017/09/08 16:55

mohenjo

inp = list(map(int,'0 15 4 0 7 10 0'.split()))

def findHG(inp):
    inp.sort(reverse = True)
    H, G, sum = 0, 0, 0
    for i in range(1, len(inp) + 1):
        sum += inp[i-1]
        if i >= inp[i-1] and H == 0:
            H = i
        if sum <= i*i and G == 0:
            G = i
    return H, G

print(findHG(inp))

2017/11/20 13:40

songci

python

L = [0, 15, 4, 0, 7, 10, 0]

def h(L):
    for i in sorted(L)[::-1]:
        h = 0
        for j in L:
            if j >= i: h += 1
        if i == h: return h

print(h(L))

def g(L, g = 0):
    G = 0
    for i in sorted(L)[::-1]:
        g += 1 ; G += i
        if g*g >= G: return g

print(g(L))

2017/11/21 15:32

이택성

def hindex(index):
    tmp=sorted(index)
    result=0
    for i in range(1, tmp[-1]+1):
        if len([x for x in tmp if x>=i])>=i:
            result=i
    return(result)

def gindex(index):
    tmp=sorted(index, reverse=True)
    result=0
    for i in range(len(tmp)):
        if sum(tmp[:i])>=(i+1)**2:
            result=i+1
    return(result)

nums=list(map(int, input('인용횟수: ').split()))
print('h-index값: {}'.format(hindex(nums)))
print('g-index값: {}'.format(gindex(nums)))

2017/12/13 02:03

빗나감

        int list[] = {0,15,4,5,7,10,0};

        ArrayList newList = new ArrayList();
        //먼저 0값은 계산에 사용되지 않으므로, 이를 제거

        for(int i=0; i<list.length; i++)
        {
            if(list[i] !=0)
            {
                newList.add(list[i]);
            }
        }

        //h개의 가능 횟수
        int maxSize = newList.size();

        boolean isMax = true;
        while(isMax)
        {
            //4번 다 true여야 함
            for(int j=0; j<newList.size(); j++)
            {
                if((int)newList.get(j) < maxSize)
                {
                    isMax = false;
                }
            }

            if(isMax == false)
            {
                maxSize--;
            }
            else
            {
                break;
            }

        }

        System.out.println("b = "+maxSize);
//•g-index : 인용 횟수가 높은 상위 g개 논문의 인용 횟수 총합이 g²이상일 때 가능한 g의 최댓값
        //a+b > 2^2

        //먼저 역순으로 정렬
        Collections.sort(newList);
        Collections.reverse(newList);

        int gVal = 0;
        int gNum = 0;
        for(int k=0; k<newList.size(); k++)
        {
            gVal += (int)newList.get(k);
            int checkNum=(k+1)*(k+1);

            if(gVal < checkNum )
            {
                gNum = k-1;
                break;
            }
            if(k == newList.size()-1)
            {
                gNum=newList.size();
            }
        }
        System.out.println("k =="+gNum);



2017/12/25 03:18

김준학

"""
- 주어진 논문 인용횟수를 내림차순으로 정렬
- 각 논문의 인용횟수가 논문의 개수 이상인지 확인하여 리스트에 추가하여 요소 개수의 최대값(h_list)을 출력
- 인용횟수가 높은 논문부터 누적합산해서 합산한 개수의 제곱이 합 이상이라는 조건을 만족할때까지 비교하여 합산 개수의 최대값(g_list)를 출력 
"""

quotation_count = [0, 15, 4 ,0 , 7 ,10 ,0]

def indexcal(x):
    h_list = []
    g_list = []
    result = 0
    x.sort(reverse=True)
    for i in x:
        result += i
        g_list.append(len(g_list))
        if i >= len(h_list):
            h_list.append(i)
        if result >= len(g_list)**2:
            g = len(g_list)
    print("h-index : %d" % len(h_list))
    print("g-index : %d" % g)


indexcal(quotation_count)   
  • 결과값
h-index : 4
g-index : 6

2017/12/25 13:17

justbegin

import java.util.Arrays;
public class hIndexgIndex {
    public static void main(String[] args) {
        int[] arr = {0, 15, 4, 0, 7, 10 ,0};

        for(int i=0; i<arr.length; i++) {
            for(int j=i; j<arr.length; j++) {
                if(arr[i]<arr[j]) {
                    int temp;
                    temp = arr[i];
                    arr[i] = arr[j];
                    arr[j] = temp;
                }
            }
        }
        System.out.println(Arrays.toString(arr));
        //g-index를 구해보자 
        int gIn=0;
        int gSum=0;
        for(int i=0; i<arr.length; i++) {
            //gIn은 인덱스 값들을 차례대로 더해나간다
            gSum = gSum + arr[i];
            if(gSum >= (i+1)*(i+1)) {
                gIn++;
            }
            else {
                break;
            }           
        }
        int hIn=1;
        for(hIn=1; hIn<arr.length; hIn++) {
            int count=0;

            for(int i=0; i<arr.length; i++) {
                if(arr[i]>=hIn) {
                    count++;
                }
            }
            if(count<hIn) {
                hIn--;
                break;
            }
        }


        System.out.println(hIn);
        System.out.println(gIn);
    }
}

2017/12/29 15:18

김기덕

input = [0, 15, 4, 0, 7, 10, 0]

def getHindex():
    test_true = []

    i = 1
    while i < max(input):
        if testHindex(i) == i:
            test_true.append(i) # 명제 true인 값 보관

        i += 1

    print(max(test_true))

# h-index를 구하는 공식 메소드화
def testHindex(h):
    count = 0

    for quote_num in input:
        if quote_num >= h:
            count += 1

    return count

def getGindex():
    test_true = []

    i = 1
    while i < len(input):
        if testGindex(i) >= pow(i, 2):
            test_true.append(i)

        i += 1

    print(max(test_true))


# g-index를 구하는 공식 메소드화
def testGindex(g):
    copy_input = input # 입력값 복사본 생성

    copy_input.sort()
    copy_input.reverse()

    sum = 0
    for quote_num in copy_input[0:g+1]: # list[0:2] - list의 [0] ~ [1]까지 추출
        sum += pow(quote_num, 2)

    return sum

2018/01/07 00:38

임지호

def hindex(preferences):
    a = preferences
    a.sort()
    a.reverse()
    h = 1
    index = 0
    while(a[h-1] >= h):
        index = h
        h += 1
    return index

def gindex(preferences):
    a = preferences
    a.sort()
    a.reverse()
    g = 1
    index = 0
    while(sum(a[:g]) >= g*g):
        index = g
        g += 1
    return index

2018/02/04 01:38

김동하

def hindex(a):
    a.sort(reverse=True)
    i=0
    while i+1<=a[i]:
        i+=1
        if i==len(a):break
    print(i)
def gindex(a):
    a.sort(reverse=True)
    g=1
    while sum(a[:g])>=g*g:
        g+=1
        if g-1==len(a):break
    print(g-1)

2018/02/07 21:46

추천은 다 읽음

def indexes():
    paper_list=raw_input('type each papers reference number:')
    a=paper_list.split(' ')
    a=[int(x) for x in a]
#h-index

    h_index=0
    i=0
    count=0

    for h_index in range(len(a)+1):
        for i in range(len(a)):
            if a[i]>=h_index:
                count +=1

        if count==h_index:
            break
        count=0
    print('h-index: %d' %(h_index))

#g-index 

    g_index=0
    i=0
    count=0

    a.sort()
    a.reverse()

    for g_index in range(len(a)+1):
        for i in range(1,len(a)+1):
            if sum(a[:i])>=g_index**2:
                count +=1

        if count<g_index:
            break
        count=0
    print('g-index: %d' %(g_index))


2018/02/13 14:13

Da ne

nNum=int(input('논문개수를 입력하세요\n'))
num_list=[]
for k in range(nNum):
    num_list.append(int(input("인용횟수를 입력하세요\n")))

for g in range(nNum,-1,-1):           
    temp_counter=0
    for c in num_list:
        if g<=c:
            temp_counter+=1
    if temp_counter==g:
        print("h-index: "+str(g))
        break

num_list.sort()
num_list.reverse()

for b in range(nNum,-1,-1):
    temp_sum=0
    for a in range(b):
        temp_sum+=num_list[a]
    if temp_sum>=b**2:
        print("g-index: "+str(b))
        break

2018/02/16 08:23

D B

"""
author: Kenny Jeon
date: 03/18/2018
"""


def func(num_list):
    h_idx = g_idx = 0
    # declare variables
    num_list.sort(reverse=True)
    # reverse sort
    for h in range(len(num_list)):
        if h_idx < num_list[h] <= h+1:
            h_idx = h+1
    # calculate h_idx

    for g in reversed(range(len(num_list))):
        if g_idx**2 < (g+1)**2 <= sum(num_list[0:g]):
            g_idx = g+1
    # calculate g_idx

    return h_idx, g_idx


if __name__ == "__main__":
    numbers = [0, 15, 4, 0, 7, 10, 0]
    h_index, g_index = func(numbers)
    print("H-index: %d, G-index: %d" % (h_index, g_index))

2018/03/18 01:22

Kenny Jeon

def indexing(*quate):
    for h in range(len(quate) + 1):
        hindex = [x for x in quate if x >= h]
        if len(hindex) < h:
            hindex = [x for x in quate if x >= h-1]
            break
    for g in range(len(quate) + 1):
        args = sorted(list(quate), reverse=True)
        gindex = args[:g]
        if sum(gindex) < g**2:
            gindex = args[:g-1]
    return (len(hindex), len(gindex))

Python 3

2018/03/29 18:44

myyh2357

파이썬으로 작성했습니다.

mylist=[ int(myli) for myli in input('').split(' ')]
h_index,g_index=mylist[0],1
mylist.sort()

for myli1 in mylist:
    count=0
    for myli2 in mylist:
        if myli1<=myli2:
            count+=1
    if count<myli1:
        break
    else:
        h_index=myli1

while True:
    if sum(mylist[-(g_index):])>=(g_index)*(g_index):
        g_index+=1
    else:
        g_index-=1
        break

print(h_index, g_index)

2018/04/20 17:52

박종범

def hgindex(string):
    lim = string.split()
    operands = []
    for x in lim:
        operands.append(int(x))

    dic = {}
    h_index = 0
    for number in operands: # h-index
        h_index = number # number 라고 가정
        count = 0
        for k in operands:
            if h_index <= k:
                count += 1                
            else:
                pass

        if h_index == count:
            dic[h_index] = count

    l1 = operands[::] # g-index
    l1.sort(reverse = True)
    lst = []
    g = 1
    dic2 = {}

    while True: # g =1 개부터 차례차례 구해봄
        a = l1[:g-1]
        total = 0
        g += 1
        for number in a:
            total = number + total

        if total > g ** 2:
            dic2[g+1] = 'answer'

        if g == len(l1):
            break

    result1 = list(dic.keys())[0]
    result2 = sorted(list(dic2.keys()))[-1]


    printing1 = "h-index: {}".format(result1)
    printing2 = "g-index: {}".format(result2)

    return printing1,printing2

print(hgindex('0 15 4 0 7 10 0'))

2018/05/07 22:14

최우성

Python

def findH(citation):
    h = 0
    for i in set(citation):
        num_i = 0
        for j in citation:
            if j >= i:
                num_i += 1#num_i는 i번 이상인 논
        if num_i >= i:
            h = max(h, i)
    return h
def findG(citation):
    a = sorted(citation, reverse=True)
    g, tmp_sum = 0, 0
    for i in range(len(a)):
        tmp_sum += a[i]
        if tmp_sum >= (i+1)**2:
            g = i+1
        else:
            break
    return g

citation = [0, 15, 4, 0, 7, 10, 0]
print(findH(citation))
print(findG(citation))

2018/06/11 15:56

Taesoo Kim

import java.util.Arrays;

public class hindexgindex {
    public static void main(String[] args) {
        int[] input = { 0, 15, 4, 0, 7, 10, 0 };
        Arrays.sort(input);
        System.out.println(H(input));
        System.out.println(G(input));
    }

    private static int H(int n[]) {
        for (int i = n[n.length - 1]; i > -1; i--) {
            int H = 0;
            for (int j = 0; j < n.length; j++)
                if (i <= n[j])
                    H++;
            if (i == H)
                return H;
        }
        return 0;
    }

    private static int G(int n[]) {
        for (int i = 1; i < n.length; i++) {
            int G = 0;
            for (int j = 1; j <= i; j++)
                G += n[n.length - j];
            if (Math.pow(i, 2) == G)
                return i;
        }
        return 0;
    }
}

2018/06/27 19:52

김지훈

def h_index(Q):
    for h in reversed(range(len(Q))):
        if len([i for i in Q if i >= h]) == h: return h
    return 0
def g_index(Q):
    Q.sort(reverse=True)
    for g in reversed(range(len(Q))):
        if sum(Q[:g]) >= g**2: return g
    return 0


Q = [int(i) for i in input('인용 횟수 입력(공백으로 구분): ').split()]

print('h-index: {}\ng-index: {}'.format(h_index(Q),g_index(Q)))

인용 횟수 입력(공백으로 구분): 0 15 4 0 7 10 0
h-index: 4
g-index: 6

2018/07/02 05:47

Creator

inp=input("각 논문의 인용 횟수를 띄어쓰기로 구분해서 입력하시오").split()
int_inp=list(map(int,inp))

#h index
hindex=0

for i in range(len(int_inp)):  #string inp에 들어있는 각각의 원소에 대하여
    count=0

    for j in range(len(int_inp)):  #i 번째 원소와 각각의 원소를 대조. 해당 원소보다 크거나 같은 원소가 있다면 count +1
        if int_inp[i]<=int_inp[j]: 
            count+=1             

    if count>=int_inp[i]:
        hindex=max(hindex,int_inp[i])

print("h-index is",hindex)


#g index
inp_sorted=sorted(int_inp, reverse=True)

gindex=0
summation=0   

for i in range(len(inp_sorted)):

    summation+=inp_sorted[i]
    gindex=i+1

    if summation<gindex**2:
        gindex=i
        print("g-index is",gindex)
        break

2018/08/23 21:01

JW Yoo

x <- c(0, 15, 4, 0, 7, 10, 0)

x_sort <- sort(x, decreasing = T)
index_h <- 0
index_g <- 0

for (i in seq(x_sort)){
  if (sum(head(x_sort, i) >= i) >= i){
    index_h <- i
  }
  if (sum(head(x_sort, i)) >= i ^ 2){
    index_g <- i
  }
}

index_h
index_g

2018/12/03 14:21

physche

def hgindex(*quot):
    quot = list(sorted(list(quot)))[::-1]

    print(list(x for x in range(len(quot),0,-1) if sum(quot[:x]) >= x**2)[0])
    print(list(x for x in range(len(quot),0,-1) if len(list(i for i in quot if i >= x)) == x)[0])

풀어서 작성한 것입니다.

def hgindex(*quot):

    quot,g,h = list(sorted(list(quot)))[::-1],[],[]

    for x in range(len(quot),0,-1):

        if sum(quot[:x]) >= x**2:
            g.append(x)

        if len(list(i for i in quot if i >= x)) == x:
            h.append(x)

    return g[0],h[0]

좀 더 빠르다고 생각하는 버전

def hgindex(*quot):

    quot,g,h = list(sorted(list(quot)))[::-1],0,0

    for x in range(len(quot),0,-1):
        if sum(quot[:x]) >= x**2:
            g = x
            break

    for x in range(len(quot),0,-1):
        if len(list(i for i in quot if i >= x)) == x:
            h = x
            break

    return g,h

원래 둘 중 하나를 쓸려 했지만 실행속도의 차이가 0.0으로 나오네요.

2019/01/23 13:17

김영성

inp1 = '0 15 4 0 7 10 0'

A = inp1.split(' ')
A = [int(x) for x in A]

# h-index
hary = []
for hind in range(0, max(A)+1):
    cnt = 0
    for Aind in range(0, len(A)):
        if A[Aind] >= hind: cnt += 1
    hary += [[hind, cnt]]
for hind in range(max(A)-1, -1, -1):
    if hary[hind][0] == hary[hind][1]:
        h_index = hind
        break

# g-index
gary1 = []
for gind in range(0, len(A)):
    gary = sorted(A, reverse = True)
for gind in range(0, len(A)):
    if gind == 0:
        gary1 = [gary[0]]
    else:
        gary1 += [gary1[gind-1] + gary[gind]]
for gind in range(len(A)-1, -1, -1):
    if gary1[gind] >= (gind+1)**2:
        g_index = gind+1
        break

print(g_index, h_index)

답: h_index = 4 g_index = 6

2019/01/29 16:14

판다네밥상

package Work;

import java.util.Arrays;

public class KimSanghyeop {

    public static void main(String args[])
    {
        int arr[] = {0,15,4,0,7,10,0};
        Arrays.sort(arr);

        int h_index=0, g_index=0;
        int cnt;
        int sum=0;
        for(int f1=0;f1<arr.length;f1++)
        {
            // G Index
            sum+=arr[arr.length-1-f1];

            if(f1*f1>=sum)
            {
                g_index=f1;
            }


            // H index
            cnt=0;
            for(int f2=0;f2<arr.length;f2++)
            {
                if(arr[f1] <=arr[f2])
                {
                    cnt+=1;
                }
            }

            if(cnt ==arr[f1] && h_index <=cnt)
            {
                h_index=cnt;
            }
        }       

        System.out.println("H Index : "+h_index);
        System.out.println("G_Index : "+g_index);
    }
}

2019/01/30 11:32

김상협

study = list(map(int, input().split()))

def h_index(study):
    study.sort()
    result = []
    for i in study:
        count = 0
        for j in study:
            if i <= j:
                count += 1
        if i == count:
            result.append(i)
    result.sort()
    return result[-1]

def g_index(study):
    study.sort(reverse=True)
    result = []
    total = 0
    count = 1
    for i in study:
        total += i
        if total >= count ** 2:
            result.append(count)
        count += 1
    result.sort()
    return result[-1]

print('h-index : {}\ng-index : {}'.format(h_index(study),g_index(study)))

2019/02/04 15:57

D.H.

def h_idx(L):
    h = 1
    while h <= len(L):
        count = sum(x >= h for x in L)
        if count < h:
            h -= 1
            break
        h += 1
    return h

def g_idx(L):
    L.sort()
    L.reverse()
    g = 1
    while g <= len(L):        
        if sum(L[:g]) < g*g:
            g -= 1
            break
        g += 1
    return g

L = list(map(int, input().split()))
print(h_idx(L))
print(g_idx(L))

2019/05/12 16:42

messi

import java.util.*;
public class h_indexG_index {

    static String[] strs = new Scanner(System.in).nextLine().split(" ");
    static int[] nums = Arrays.stream(strs).mapToInt(Integer::parseInt).toArray();

    public static void main(String[] args) {
        h_Index();
        g_Index();
    }

    public static void h_Index(){
        Arrays.sort(nums);
        int h최댓값 = 0;
        for(int i=0; i<nums.length; i++) {
            int count = 0;
            for(int j=0; j<nums.length; j++) {
                if(nums[j]>=nums[i]) {
                    count++;
                }
            }
            if(nums[i]==count) {
                if(count>h최댓값) {
                    h최댓값=count;
                }
            }
        }
        System.out.println("h-index : "+h최댓값);
    }

    public static void g_Index() {
        Arrays.sort(nums);
        int 최댓값 = 0;
        for(int i=0; i<nums.length; i++) {
            int 총합 = 0;
            for(int j=nums.length-1; j>nums.length-2-i; j--) {
                총합+=nums[j];
            }
            if(총합>=(i+1)*(i+1)) {
                if(i+1>최댓값) {
                    최댓값 = i+1;
                }
            }
        }
        System.out.println("g-index : "+최댓값);
    }
}

2019/11/25 19:01

big Ko


data = [0,15,4,0,7,10,0]

h_index = 0

for i in data:    
    value = 0
    for j in data:
        if i >= j :
            value +=1            
    if i == value :
        h_index = i

print("h-index :",h_index)    

g=len(data)
Count = g
g_index = 0

data.sort()
Run =True
while Run:

    data_sum = 0
    for k in data:
        data_sum += k

    data.remove(k)
    Count -=1

    for l in range(g,0,-1):                
        if data_sum >= l**2 :
            break
    Run = False

    g_index = l


print("g-index :",g_index)


2020/01/20 23:57

semipooh

index=str(input('input.....')).split(' ')
gmax,hmax=0,0

for i in range(len(index)):
    index[i]=int(index[i])
index.sort(reverse=True)

for i in range (1,len(index)):
    n,gsum=0,0

    for j in range (0,len(index)):
        if index[j]>=i:
            n+=1
    if hmax<n and n==i:
        hmax=n

    for j in range (0,i):
        gsum+=index[j]  
    if gsum>=i**2:
        if i>gmax:
            gmax=i

print ('h-index : ',hmax,'\ng-index : ',gmax)

2020/04/15 18:37

Buckshot

<결과> input.....0 15 4 0 7 10 0 h-index : 4 g-index : 6 - Buckshot, 2020/04/15 18:37
def hg(tn):
    tn_s = sorted(tn, reverse=True)
    dict = {'h': 0, 'g': 0}
    for i in tn:
        if i == len([j for j in tn if j >= i]):
            if dict['h'] < i:
                dict.update(h=i)

    for j in range(len(tn_s), 0, -1):
        if (j**2) <= sum(tn_s[:j+1]):
            if dict['g'] < j:
                dict.update(g=j)

    return dict['h'], dict['g']

def main():
    thesis_num = [0, 15, 4, 0, 7, 10, 0]
    h, g = hg(thesis_num)
    print('h-index: {}\ng-index: {}'.format(h, g))

if __name__ == '__main__':
    main()

2020/05/03 16:09

Hwaseong Nam

paper = list((str(input()).split()))
paper = list(map(int, paper))
paper.sort()
h_index = []
g_index = []
for i in range(0,max(paper)):
    cnt = 0
    for j in paper:
        if i <= j:
            cnt += 1
        else:
            continue
    if i == cnt:
        h_index.append(i)
    else:
        continue
for g in range(1,len(paper)+1):
    if sum(paper[-1:-(g+1):-1]) >= len(paper[-1:-(g+1):-1])**2:
        g_index.append(g)    
print('h-index:',max(h_index))
print('g-index:',max(g_index))    

2020/05/14 13:14

Money_Coding

num="0 15 4 0 7 10 0"

def h_index(num) :
    num = num.split(" ")
    number = []

    for i in range(0, (len(num))) :
        number += [int(num[i])]
    number.sort()
    k=1

    while k > 0 :
        if number[-k] >= k :
            k+=1
            continue
        else :
            print(k-1)
            break

h_index(num)

num="0 15 4 0 7 10 0"

def g_index(num) :
    num = num.split(" ")
    number = []
    for i in range(0, (len(num))) :
        number += [int(num[i])]
    number.sort()

    k=1
    while k > 0 :
        if sum(number[-k:]) >= k**2 :
            k+=1
            continue
        else :
            print(k-1)
            break

g_index(num)

2020/09/25 09:18

KangJin Moon

index = list(map(int, input().split(" ")))
index.sort()
h_index = []
g_index = []
for i in range(0, max(index) + 1):
    count = 0
    for k in index:
        if k >= i:
            count += 1
    h_index.append(count)
    if h_index[i] == i:
        print("h-index : " + str(i))
        break
for i in range(0, max(index) + 1):
    if sum(index[-i:]) >= i**2:
        g_index.append(i)
print("g-index : " + str(max(g_index)))

2020/11/26 20:51

김우석

def main():

print(h_index([0,15,4,0,7,10,0]))

print(g_index([0,15,4,0,7,10,0]))

def h_index(lista):

lenght=len(lista)

for i in range(lenght,0,-1):

  count=0

  for j in lista:

    if j>=i:

      count+=1

  if count==i:

    return i

    break

def g_index(listb):

listb.sort()

listb.reverse()

length=len(listb)

for i in range(length,0,-1):

  sumnumber=0

  for j in range(0,i,1):

    sumnumber+=listb[j]

  if sumnumber>=i*i:

    return i

    break

main()

2021/01/02 20:14

전준혁

def h_index(list_input):
    value_h = 0

    for i in range(max(list_input)+1):
        count = 0
        for aa in list_input:
            if aa >= i:
                count += 1
        if i <= count :
            value_h = i

    return print('VALUE H : ', value_h)

def g_index(list_input):
    value_g = 0

    for i in range(len(list_input)):
        sum = 0
        for member in sorted(list_input, reverse=True)[0:i:]:
            sum += member
            if sum >= i**2:
                value_g = i

    return print('VALUE G : ', value_g)


h_index([0, 15, 4, 0, 7, 10, 0])
g_index([0, 15, 4, 0, 7, 10, 0])        

2021/03/09 08:51

DSHIN

def hIndex(a):
    b=[]
    count=0
    for i in a:
        if min(a)<=i:
            count+=1
            if min(a)<=count:
                b.append(min(a))
                a.remove(min(a))  
    print(max(b))
a = [0,15,4,0,7,10,0]
hIndex(a)

def gIndex(a):
    b=[]
    count=0
    for i in a:
        if min(a)<=i:
            count+=1
            if sum(a)>=count**2:
                b.append(count)
    print(max(b))

a = [0,15,4,0,7,10,0]
gIndex(a)

2021/03/17 21:19

fox.j

input = list(map(int,'0 15 4 0 7 10 0'.split(' ')))

for i in range(len(input)):
    times = 0
    for j in input:
        if j >= i:
            times += 1
    if times == i:
        print('h-index:',i)
        break

input.sort(reverse = True)
for i in range(len(input)):
    if sum(input[0:i]) >= i**2:
     print('g-index:',i)
     break

2021/07/06 16:23

ss2663

#codingdojing_h&g_index
#내림차순으로 정렬해서 계산. 조건이 맞지 않는 경우를 찾으면 break

a = list(map(int, input('IF: ').split()))
a.sort(reverse = True) #[15, 10, 7, 4, 0, 0, 0]

def h_index(a):
    for i in range(len(a)):
        if a[i] >= i+1: continue 
        else: 
            return i
            break
    return len(a) #전체 논문수에 해당될 때

def g_index(a):
    for i in range(len(a)):
        if sum(a[:i+1]) >= (i+1)**2: continue 
        else: 
            return i
            break
    return len(a) #전체 논문수에 해당될 때

h = h_index(a)
g = g_index(a)

print(f'h-index: {h}')
print(f'g-index: {g}')

2021/08/13 18:20

Jaeman Lee


arr = [0,15,4,0,7,10,0]

def H_index(arr):
    a=sorted(arr)
    h_arr =[]
    for i in a :
        n=0
        h =i
        for k in a :
            if k>=h:
                n+=1
        if h==n :
            h_arr.append(h)
    return print("h-index : ",max(h_arr))

def G_index (arr):
    a=list(reversed(sorted(arr)))
    g_arr=[]
    sum =0
    for i in range(len(a)):
        sum+=a[i]
        g=i+1
        if sum>=g**2:
            g_arr.append(g)
    return print("g-index : ",max(g_arr))
H_index(arr)
G_index(arr)

2022/01/03 22:26

양캠부부

// Rust

fn index(vec_: Vec) -> (usize, usize) {

let mut vec = vec_;
vec.sort();
vec.reverse();
let mut h_index = 0;
let mut g_index = 0;

for i in (1..=vec.len()).rev() {

    // h-index : 인용이 h이상인 논문이 h개 이상
    let mut count = 0;
    for v in &vec {
        if h_index > 0 { break; }
        if *v >= i {
            count += 1;
        }
    }
    if count >= i {
        h_index = i;
    }

    // g-index : 인용상위 g개 논문의 인용횟수 합이 g^2 이상
    if g_index > 0 { continue; }
    if vec[..i].iter().sum::<usize>() >= i.pow(2) {
        g_index = i;
    }
}
(h_index, g_index)

}

[test]

fn test() {

assert_eq!(index(vec![0,15,4,0,7,10,0]), (4, 6));

}

2022/01/27 21:19

JW KIM

cit = '0 15 4 0 7 10 0'
cit_num_list=[]
for i in cit.split(' '): 
    if int(i) not in cit_num_list: 
        cit_num_list.append(int(i))

cit_num_list.sort()
print(f'cit_num_list :   {cit_num_list}')
paper_num_list = [cit.split(' ').count(str(x)) for x in cit_num_list]
print(f'paper_num_list : {paper_num_list}')

h_list = [(cit_num_list[x] , sum(paper_num_list[x:])) for x in range(5)]
print(f'h_list : {h_list}')
print(f'h-index : {max([x[0] for x in h_list if x[0] <= x[1]])}')

cit_num = list(map(int,cit.split(' ')))
cit_num.sort()
print(f'cit_num : {cit_num[::-1]}')

g_list = [sum(cit_num[::-1][:x+1]) for x in range(len(cit_num[::-1]))]
print(f'g_list  : {g_list}')
g_list_index = [x+1 for x in range(len(cit_num[::-1])) if g_list[x]>=(x+1)**2]
print(f'g_list_index  : {g_list_index}')
print(f'g-index : {max(g_list_index)}')

2022/02/15 15:40

로만가

package org.javaturotials.ex;
import java.util.*;
import java.util.stream.Collectors;

public class test {
    public static void main(String[] args) {    
    Scanner sc =new Scanner(System.in);
    int max = 0;
    int sum=0;
    int gdex = 0;
    String str = sc.nextLine();
    String[] arr =str.split(" ");
    int[] irr = new int[arr.length];
    for(int i=0; i<arr.length; i++){
        irr[i] = Integer.valueOf(arr[i]);
    }
    for(int i=0; i<irr.length; i++) {
        int count = 0;
        for(int j=0; j<irr.length; j++) {
            if(irr[i]<=irr[j]) {
                count++;
            }
        }
        sum+=irr[i];
        if(count==irr[i]) {
            max=count;
            }   
    }
        gdex = (int)Math.sqrt(sum);
    System.out.println("h-index: " +  max);
    System.out.println("g-index: " +  gdex);
    }
    }

2022/02/22 19:24

Kkubuck

목록으로