일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
- Git
- ChatGPT
- Kaggle
- programmers
- github
- AI 경진대회
- dacon
- 데이콘
- leetcode
- 우분투
- 맥북
- ubuntu
- 프로그래머스
- 캐치카페
- 금융문자분석경진대회
- 편스토랑 우승상품
- 백준
- 더현대서울 맛집
- 파이썬
- Docker
- 편스토랑
- Baekjoon
- 코로나19
- hackerrank
- SW Expert Academy
- gs25
- 프로그래머스 파이썬
- 자연어처리
- PYTHON
- Real or Not? NLP with Disaster Tweets
- Today
- Total
솜씨좋은장씨
[HackerRank] Grading Students (Python) 본문
HackerLand University has the following grading policy:
- Every student receives a grade in the inclusive range from 0 to 100.
- Any grade less than 40 is a failing grade.
Sam is a professor at the university and likes to round each student's grade according to these rules:
- If the difference between the grade and the next multiple of 5 is less than 3, round grade up to the next multiple of 5.
- If the value of grade is less than 38, no rounding occurs as the result will still be a failing grade.
For example, grade = 84 will be rounded to 85 but grade = 29 will not be rounded because the rounding would result in a number that is less than 40.
Given the initial value of grade for each of Sam's n students, write code to automate the rounding process.
Function Description
Complete the function gradingStudents in the editor below. It should return an integer array consisting of rounded grades.
gradingStudents has the following parameter(s):
- grades: an array of integers representing grades before rounding
Input Format
The first line contains a single integer, n, the number of students.
Each line i of the n subsequent lines contains a single integer, grades[ i ], denoting student 's i grade.
Constraints
- 1 <= n <= 60
- 0 <= grades [ i ] <= 100
Output Format
For each grades [ i ], print the rounded grade on a new line.
Sample Input 0
4
73
67
38
33
Sample Output 0
75
67
40
33
Explanation 0
- Student 1 received a 73, and the next multiple of 5 from 73 is 75. Since 75 - 73 < 3, the student's grade is rounded to 75.
- Student 2 received a 67, and the next multiple of 5 from 67 is 70. Since 70 - 67 = 3, the grade will not be modified and the student's final grade is 67.
- Student 3 received a 38, and the next multiple of 5 from 38 is 40. Since 40 - 38 < 3, the student's grade will be rounded to 40.
- Student 4 received a grade below 38, so the grade will not be modified and the student's final grade is 33.
Solution
#!/bin/python3
import math
import os
import random
import re
import sys
#
# Complete the 'gradingStudents' function below.
#
# The function is expected to return an INTEGER_ARRAY.
# The function accepts INTEGER_ARRAY grades as parameter.
#
def gradingStudents(grades):
answer = []
for grade in grades:
if grade < 38 or (grade % 5 < 3):
score = grade
else:
mod_num = grade % 5
round_num = 5 - mod_num
score = grade + round_num
answer.append(score)
return answer
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()
'Programming > 코딩 1일 1문제' 카테고리의 다른 글
[Programmers] 124 나라의 숫자 (Python) (0) | 2020.04.30 |
---|---|
[HackerRank] Day of Programmer (Python) (0) | 2020.04.29 |
[BaekJoon] 10866번 : 덱 (Python) (0) | 2020.04.27 |
[BaekJoon] 1158번 : 요세푸스 문제 (Python) (0) | 2020.04.26 |
[BaekJoon] 1463번 : 1로 만들기 (Python) (0) | 2020.04.25 |