Fascination
article thumbnail

[문제]

 

Grading Students | HackerRank

Round student grades according to Sam's rules.

www.hackerrank.com

 

 

[문제 설명]

- 학생들의 최종 성적을 구하는 문제

- 38점 이하의 점수를 받는 학생들은 반올림된 점수를 받지 못함

- 학생들의 점수를 반올림 할 수 있는 경우에 대하여는 반올림한 성적을 반영함

 

 

[문제 풀이]

- 일의 자리가 5인 점수와 그렇지 않은 점수를 구별해야 함

- 100점일 때와 낙제점 38점 이하일 때에 대하여 예외처리 필요

- 일의 자리가 5 아래일 경우 해당 점수의 십의자리에 해당하는 숫자*10+5와 주어진 점수의 차를 비교하여 최종 성적을 구함

- 일의 자리가 5이상일 경우 해당 점수의 십의 자리에 해당하는 숫자*10+10과 주어진 점수의 차를 비교하여 최종 성적을 구함

 

 

[코드]

vector<int> gradingStudents(vector<int> grades) {
    int score=0;
    for(int i=0;i<grades.size();i++){
        score = grades[i];
        if(score == 100) {
            grades[i]=100;
            continue;
        }
        
        if(score%10<5){
            if ((score/10*10+5)-score<3) grades[i]= score-score%10+5;
            else grades[i]=score;
        }
        else{
            if ((score/10*10+10)-score<3) grades[i]= score/10*10+10;
            else grades[i]=score;
        }
        if(score<38) grades[i]=score;
    }
    
    return grades;
}

 

[실행 결과]

'CODE > HackerRank' 카테고리의 다른 글

[C++] HackerRank : Compare the Triplets  (0) 2021.10.03
[C++] HackerRank : Plus Minus  (0) 2021.10.03
[C++] HackerRank : Equal Stacks  (0) 2021.10.03
[C++] HackerRank : Simple Array Sum  (0) 2021.09.21
[C++] HackerRank : Diagonal Difference  (0) 2021.09.21
profile

Fascination

@euna-319

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!