Grading Students – HackerRank Solution Java , Python 3, Python 2 , C , C++, Best and Optimal Solutions , All you need.
C++ Grading Students HackerRank Solution
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std;
int main(){
int n;
cin >> n;
for(int a0 = 0; a0 < n; a0++){
int grade;
cin >> grade;
if (grade >= 38) {
int rem = grade % 5;
if (rem >= 3) grade += 5 - rem;
}
cout << grade << endl;
}
return 0;
}
Java Grading Students HackerRank Solution
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
for(int a0 = 0; a0 < n; a0++){
int grade = in.nextInt();
if (grade >= 38) {
if (grade % 5 >= 3) {
grade += 5 - (grade % 5);
}
}
System.out.println(grade);
}
}
}
Python 3 Grading Students HackerRank Solution
#!/bin/python3
import sys
n = int(input().strip())
for a0 in range(n):
x = int(input().strip())
if x >= 38:
if x % 5 > 2:
while x % 5 != 0: x += 1
print(x)
Python 2 Grading Students HackerRank Solution
#!/bin/python
import sys
n = int(raw_input().strip())
for a0 in xrange(n):
grade = int(raw_input().strip())
# your code goes here
if grade < 38:
print grade
continue
if grade % 5 >= 3:
grade = ((grade / 5) + 1) * 5
print grade
C Grading Students HackerRank Solution
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>
int main(){
int n;
scanf("%d",&n);
for(int a0 = 0; a0 < n; a0++){
int grade;
scanf("%d",&grade);
// your code goes here
int x = (grade+4)/5;
x *= 5;
if(x>=40 && x-grade<3)grade=x;
printf("%d\n",grade);
}
return 0;
}