- 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. Read full question on hackerrank.
Solution in C# -
class Result
{
public static List<int> gradingStudents(List<int> grades)
{
List<int> roundedGrades = new List<int>();
for(int i=0; i<grades.Count; i++)
{
int x = grades[i]/5;
x++;
int y = x*5;
if(y-grades[i] < 3 && grades[i] >= 38)
roundedGrades.Add(y);
else
roundedGrades.Add(grades[i]);
}
return roundedGrades;
}
}
class Solution
{
public static void Main(string[] args)
{
TextWriter textWriter = new StreamWriter(@System.Environment.GetEnvironmentVariable("OUTPUT_PATH"), true);
int gradesCount = Convert.ToInt32(Console.ReadLine().Trim());
List<int> grades = new List<int>();
for (int i = 0; i < gradesCount; i++)
{
int gradesItem = Convert.ToInt32(Console.ReadLine().Trim());
grades.Add(gradesItem);
}
List<int> result = Result.gradingStudents(grades);
textWriter.WriteLine(String.Join("\n", result));
textWriter.Flush();
textWriter.Close();
}
}
Post a Comment