[HackerRank] Grading Students

in kr •  6 years ago 

algorithm.png

문제



출처 - HackerRank


풀이


나머지 연산을 이용합니다.

public class Solution {
    static int[] gradingStudents(int[] grades) {
        
        for (int i = 0; i < grades.length; i++) {
            // 점수가 38점 이상이며 5로 나눈 나머지가 3 이상이면 반올림
            if (grades[i] >= 38 && (grades[i] % 5) >= 3) {
                grades[i] += 5 - (grades[i] % 5);
            }
        }
        
        return grades;
    }
}


Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!