Archive/Code_HackerRank 2018. 1. 18. 23:13

[HackerRank]Grading Students

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.

For example,  will be rounded to  but  will not be rounded because the rounding would result in a number that is less than .

Given the initial value of  for each of Sam's  students, write code to automate the rounding process. Complete the function solve that takes an integer array of all grades, and return an integer array consisting of the rounded grades. For each , round it according to the rules above and print the result on a new line.

Input Format

The first line contains a single integer denoting  (the number of students). 
Each line  of the  subsequent lines contains a single integer, , denoting student 's grade.

Constraints

Output Format

For each  of the  grades, 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

image

  1. Student  received a , and the next multiple of  from  is . Since , the student's grade is rounded to .
  2. Student  received a , and the next multiple of  from  is . Since , the grade will not be modified and the student's final grade is .
  3. Student  received a , and the next multiple of  from  is . Since , the student's grade will be rounded to .
  4. Student  received a grade below , so the grade will not be modified and the student's final grade is .




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
31
32
33
34
35
36
#include <bits/stdc++.h>
 
using namespace std;
 
vector < int > solve(vector < int > grades){
    vector<int> result;
    for(int i=0; i<grades.size(); i++){
        if(grades[i]%5>=3 && grades[i]>=38){
            result.push_back(((grades[i]/5)+1*5);
        }
        else{
       
            result.push_back(grades[i]);

        }
        
    }
    return result;
}
 
int main() {
    int n;
    cin >> n;
    vector<int> grades(n);
    for(int grades_i = 0; grades_i < n; grades_i++){
       cin >> grades[grades_i];
    }
    vector < int > result = solve(grades);
    for (ssize_t i = 0; i < result.size(); i++) {
        cout << result[i] << (i != result.size() - 1 ? "\n" : "");
    }
    cout << endl;
    
 
    return 0;
}
cs




Comment


38 이상이면 다 5 단위로 반올림.

어려운 문제는 아니었다.

'Archive > Code_HackerRank' 카테고리의 다른 글

[HackerRank]Apple and Orange  (0) 2018.01.18
[HackerRank]Time Conversion  (0) 2018.01.17
[HackerRank]Birthday Cake Candles  (0) 2018.01.17
[HackerRank]Mini-Max Sum  (0) 2018.01.17
[HackerRank]Staircase  (0) 2018.01.17