This is a personal memo.
--If the difference between (1) the score and (2) the next multiple of 5 of the score is less than 3, round (1) to (2). --If the score is less than 38 (less than), it will not be rounded.
▼sample input
python
73
67
38
33
▼sample output
python
75
67
40
33
▼my answer
python
def gradingStudents(grades):
finals=[]
for grade in grades:
if grade >= 38:
a = str(grade)[1]
if a == "3":
grade += 2
elif a=="4":
grade += 1
elif a=="8":
grade += 2
elif a=="9":
grade += 1
finals.append(grade)
return finals
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
grades_count = int(input().strip())
grades = []
for _ in range(grades_count):
grades_item = int(input().strip())
grades.append(grades_item)
result = gradingStudents(grades)
fptr.write('\n'.join(map(str, result)))
fptr.write('\n')
fptr.close()
■ Way of thinking -The difference from the next multiple of 5 is less than 3 only when the 1st place is 3,4,8,9.
■ Notes Pass for 1 digit. (The second digit does not exist) The output is passed as an array. (Return array) 「fptr.write('\n'.join(map(str, result)))」
** ・ next multiple of n ** A multiple of n.
If the difference between the grade and the next multiple of 5 is less than 3, round up to the next multiple of 5.
If the difference between the score and a value that is a multiple of 5 that is close to that score is 3 or less, the value that is a multiple of 5 is rounded.
** ・ constraints ** Constraints. Numerical conditions. 1 <n <100 etc.
Recommended Posts