Grading Students Solution in Java | HackerRank | Grading Students HackerRank Solution


Grading Students Solution in Java | HackerRank | Grading Students HackerRank Solution


Grading Students Solution HackerRank

Grading Students Solution in Java
Grading Students HackerRank Solution in Java


Problem:

Given a time in -hour AM/PM format, convert it to military (24-hour) time.

Note: Midnight is 12:00:00AM on a 12-hour clock, and 00:00:00 on a 24-hour clock. Noon is 12:00:00PM on a 12-hour clock, and 12:00:00 on a 24-hour clock.

Function Description

Complete the timeConversion function in the editor below. It should return a new string representing the input time in 24 hour format.

timeConversion has the following parameter(s):

  • s: a string representing time in  hour format

Input Format

A single string  containing a time in -hour clock format (i.e.:  or ), where  and .

Constraints

  • All input times are valid

Output Format

Convert and print the given time in -hour format, where .

Sample Input 0

07:05:45PM

Sample Output 0

19:05:45


https://www.hackerrank.com/challenges/grading-students/problem

Grading Students HackerRank Solution in Java 
Grading Students  Solution in Java

import java.io.*; import java.math.*; import java.security.*; import java.text.*; import java.util.*; import java.util.concurrent.*; import java.util.function.*; import java.util.regex.*; import java.util.stream.*; import static java.util.stream.Collectors.joining; import static java.util.stream.Collectors.toList; class Result { public static List gradingStudents(List grades) { List<Integer> temp=new ArrayList(); for(int i=0;i<grades.size();i++){ int m=grades.get(i); if(m>=38){ if((m%5)>=3){ m+=(5-(m%5)); } } temp.add(m); } return temp; } } public class Solution { public static void main(String[] args) throws IOException { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH"))); int gradesCount = Integer.parseInt(bufferedReader.readLine().trim()); List<Integer> grades = IntStream.range(0, gradesCount).mapToObj(i -> { try { return bufferedReader.readLine().replaceAll("\\s+$", ""); } catch (IOException ex) { throw new RuntimeException(ex); } }) .map(String::trim) .map(Integer::parseInt) .collect(toList()); List<Integer> result = Result.gradingStudents(grades); bufferedWriter.write( result.stream() .map(Object::toString) .collect(joining("\n")) + "\n" ); bufferedReader.close(); bufferedWriter.close(); } }

Post a Comment

0 Comments