1. 문제
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.
Examples
round to (85 - 84 is less than 3)
do not round (result is less than 40)
do not round (60 - 57 is 3 or higher)
Given the initial value of for each of Sam’s students, write code to automate the rounding process.
Function Description
Complete the function gradingStudents in the editor below.
gradingStudents has the following parameter(s):
int grades[n]: the grades before rounding
Returns
int[n]: the grades after rounding as appropriate
Input Format
The first line contains a single integer, , the number of students.
Each line of the subsequent lines contains a single integer, .
Constraints
Sample Input 0
4
73
67
38
33
Sample Output 0
75
67
40
33
Explanation 0
Student received a , and the next multiple of from is . Since , the student’s grade is rounded to .
Student received a , and the next multiple of from is . Since , the grade will not be modified and the student’s final grade is .
Student received a , and the next multiple of from is . Since , the student’s grade will be rounded to .
Student received a grade below , so the grade will not be modified and the student’s final grade is .
2. 컴퓨팅 사고
문제를 읽어보면 검색하려는 값들이 38 이하일 경우에는 해당값을 반올림을 수행하지 않는다고 합니다.
no rounding occurs as the result will still be a failing grade.
그리고, 나눈 나머지 값이 3,4,5인경우 5를 올려주고 8,9,0일 경우 10단위를 바꾸어가면서 숫자를 올려나갑니다. 즉, 나머지가 3이상일 경우 반올림의 기준이되는 5의 값에서 나머지 값을 빼주면 반올림을 하는 값을 구해줄 수 있게 됩니다. 나머지가 3이 아닐 경우에는 현재 기존의 값을 리스트에 담아주게됩니다.
Student received a , and the next multiple of from is . Since , the student's grade is rounded to . Student received a , and the next multiple of from is . Since , the grade will not be modified and the student's final grade is . Student received a , and the next multiple of from is . Since , the student's grade will be rounded to . Student received a grade below , so the grade will not be modified and the student's final grade is .
다음과 같은 테스트케이스에 잘 설명되어있으니 한번 잘 읽어보시면 될 것 같습니다.
3. 풀이
1 | import java.io.*; |