Hackerrank Grading Students Problem Solution in C
#include <stdio.h> int main(void) { // your code goes here int t,n,i,ans; scanf("%d",&t); for(i=1;i<=t;i++) { scanf("%d",&n); if(n<38 || n%5==0 || n%5==1 || n%5==2) { printf("%d\n",n); } else if(n%5==3) { ans=n+2; printf("%d\n",ans); } else if(n%5==4) { ans=n+1; printf("%d\n",ans); } } return 0; }
Hackerrank Grading Students Problem Solution in JavaScript
process.stdin.resume(); process.stdin.setEncoding('ascii'); var input_stdin = ""; var input_stdin_array = ""; var input_currentline = 0; process.stdin.on('data', function (data) { input_stdin += data; }); process.stdin.on('end', function () { input_stdin_array = input_stdin.split("\n"); main(); }); function readLine() { return input_stdin_array[input_currentline++]; } /////////////// ignore above this line //////////////////// function main() { var n = parseInt(readLine()); for(var a0 = 0; a0 < n; a0++){ var grade = parseInt(readLine()); if(grade >= 38){ var closest = Math.ceil(grade / 5) * 5; var diff = closest - grade; if(diff < 3){ grade = closest; } } console.log(grade); } }
Hackerrank Grading Students Problem Solution in Python
#!/bin/python3 import sys n = int(input().strip()) for a0 in range(n): grade = int(input().strip()) if grade > 37: if grade % 5 > 2: grade = grade + 5 - grade % 5 print (grade)
0 Comments