다시 풀어봐
- User
다시 풀어봐
Assistant
H-index 문제를 다시 차근차근 분석해보겠습니다.
H-index의 정의를 다시 정리하면:
- h개 이상의 논문이 각각 h번 이상 인용되었을 때의 최대 h값
다른 접근 방법으로 해결해보겠습니다:
def calculate_h_index(n, citations): # 가능한 모든 h값에 대해 확인 (0부터 n까지) h_index = 0 for h in range(n + 1): # h번 이상 인용된 논문의 개수를 센다 count = 0 for citation in citations: if citation >= h: count += 1 # h개 이상의 논문이 h번 이상 인용되었다면 if count >= h: h_index = h return h_index # 입력 처리 t = int(input()) for _ in range(t): n = int(input()) citations = list(map(int, input().split())) print(calculate_h_index(n, citations))
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.