def solution(answers):
pattern1 = [1, 2, 3, 4, 5] * 2000
pattern2 = [2, 1, 2, 3, 2, 4, 2, 5] * 1250
pattern3 = [3, 3, 1, 1, 2, 2, 4, 4, 5, 5] * 1000
answer_patterns = [pattern1, pattern2, pattern3]
top_students = []
student_results = []
max_correct = 0
for i, pattern in enumerate(answer_patterns, start=1):
correct_count = 0
for ans, user_ans in zip(pattern, answers):
if ans == user_ans:
correct_count += 1
max_correct = max(max_correct, correct_count)
student_results.append((i, correct_count))
for student in student_results:
if student[1] == max_correct:
top_students.append(student[0])
return top_students
sizes = [[60, 50], [30, 70], [60, 30], [80, 40]]
>> 4000
세 가지 답안 패턴인 pattern1, pattern2, pattern3을 정의한다. 이 패턴들은 주어진 답안의 길이와 일치하도록 여러 번 반복된다.
각 패턴에 대해 반복하며 해당 패턴과 주어진 답안의 해당 요소를 비교한다. 각 정답에 대해 correct_count 변수가 증가된다. 최대 정답 수는 max_correct 변수를 사용하여 추적된다.
각 패턴의 정답 수를 세고 나면, 코드는 student_results 목록을 반복하여 최대 정답 수를 가진 학생들을 찾는다. student_results 목록은 학생 번호와 해당 학생의 정답 수를 포함하는 튜플을 저장한다.
최우수 학생들의 학생 번호를 top_students 목록에 추가하고 결과로 반환한다.