1 minute read

Grading Students (Hacker Rank)

HackerLand University has the following grading policy:

Every student receives a in the inclusive range from to . Any less than is a failing grade. Sam is a professor at the university and likes to round each student’s according to these rules:

If the difference between the and the next multiple of is less than , round up to the next multiple of . If the value of is less than , no rounding occurs as the result will still be a failing grade. For example, will be rounded to but will not be rounded because the rounding would result in a number that is less than .

Given the initial value of for each of Sam’s students, write code to automate the rounding process. For each , round it according to the rules above and print the result on a new line.

#!/bin/python3

import sys

def solve(grades):
    result = []
    for grade in grades:
        next = grade if grade % 5 == 0 else grade - (grade%5) + 5
        if grade < 38:
            result.append(grade)
        elif next - grade < 3:
            result.append(next)
        else:
            result.append(grade)
    return result
    # Complete this function

n = int(input().strip())
grades = []
grades_i = 0
for grades_i in range(n):
   grades_t = int(input().strip())
   grades.append(grades_t)
result = solve(grades)
print ("\n".join(map(str, result)))
행운의 77문제 프로젝트
  행운의 77문제 프로젝트는 한 달동안 알고리즘 문제 77개를 푸는 프로젝트입니다.