일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 프로그래머스
- 코플릿
- 개발자_조이킴
- Programmers
- 코딩공부
- array
- JavaScript
- 블록체인
- 정규표현식
- node.js
- select
- Where
- 배열
- 개발자의 책장
- 최강의 인생
- Algorithms
- 알고리즘
- SQL
- Hackerrank
- 코드스테이츠
- array.push()
- 자바스크립트
- 역행자
- MySQL
- Developer_JoyKim
- for문
- array.slice()
- 코딩테스트
- join
- 재귀함수
Archives
- Today
- Total
CodingSpace
[HackerRank/Algorithms] Warmup - Grading Students 본문
Problem. Warmup - Grading Students
Link.
https://www.hackerrank.com/challenges/grading/problem?isFullScreen=true
Grading Students | HackerRank
Round student grades according to Sam's rules.
www.hackerrank.com
Description.
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 according to these rules:
- If the difference between the 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.
Given the initial value of grade for each of Sam's n students, write code to automate the rounding process.
Key Point.
My Answer.
'use strict';
const fs = require('fs');
process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', function(inputStdin) {
inputString += inputStdin;
});
process.stdin.on('end', function() {
inputString = inputString.split('\n');
main();
});
function readLine() {
return inputString[currentLine++];
}
/*
* Complete the 'gradingStudents' function below.
*
* The function is expected to return an INTEGER_ARRAY.
* The function accepts INTEGER_ARRAY grades as parameter.
*/
function gradingStudents(grades) {
// Write your code here
let answer = [];
for(let i = 0; i < grades.length; i++) {
if(grades[i] < 38 || (Math.ceil(grades[i] / 5) * 5) - grades[i] >= 3)
answer.push(grades[i]);
else
answer.push(Math.ceil(grades[i] / 5) * 5);
}
return answer;
}
function main() {
const ws = fs.createWriteStream(process.env.OUTPUT_PATH);
const gradesCount = parseInt(readLine().trim(), 10);
let grades = [];
for (let i = 0; i < gradesCount; i++) {
const gradesItem = parseInt(readLine().trim(), 10);
grades.push(gradesItem);
}
const result = gradingStudents(grades);
ws.write(result.join('\n') + '\n');
ws.end();
}
References.
'HackerRank > Algorithm' 카테고리의 다른 글
[HackerRank/Algorithms] Implementation - Cats and a Mouse (0) | 2022.08.30 |
---|---|
[HackerRank/Algorithms] Implementation - Number Line Jumps (0) | 2022.08.29 |
[HackerRank/Algorithms] Warmup - Time Conversion (0) | 2022.08.23 |
[HackerRank/Algorithms] Warmup - Birthday Cake Candles (0) | 2022.08.22 |
[HackerRank/Algorithms] Warmup - Mini-Max Sum (0) | 2022.08.22 |
Comments